MCPcopy Create free account
hub / github.com/PlutoLang/Pluto / luaopen_vector3

Function luaopen_vector3

src/lvector3lib.cpp:10–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8};
9
10LUAMOD_API int luaopen_vector3(lua_State* L) {
11#ifdef PLUTO_DONT_LOAD_ANY_STANDARD_LIBRARY_CODE_WRITTEN_IN_PLUTO
12 return 0;
13#else
14 const auto code = R"EOC(pluto_use "0.6.0"
15
16local vector3
17 class vector3
18 __name = "pluto:vector3"
19
20 function __construct(x, y, z)
21 if x ~= nil and y == nil and z == nil then
22 -- (a) -> (a, a, a)
23 self.x = x
24 self.y = x
25 self.z = x
26 else
27 -- (a, b) -> (a, b, 0)
28 -- (a, b, c) -> (a, b, c)
29 self.x = x ?? 0
30 self.y = y ?? 0
31 self.z = z ?? 0
32 end
33 end
34
35 function __add(b)
36 if b instanceof vector3 then
37 return new vector3(self.x + b.x, self.y + b.y, self.z + b.z)
38 end
39 return new vector3(self.x + b, self.y + b, self.z + b)
40 end
41
42 function __sub(b)
43 if b instanceof vector3 then
44 return new vector3(self.x - b.x, self.y - b.y, self.z - b.z)
45 end
46 return new vector3(self.x - b, self.y - b, self.z - b)
47 end
48
49 function __mul(b)
50 if b instanceof vector3 then
51 return new vector3(self.x * b.x, self.y * b.y, self.z * b.z)
52 end
53 return new vector3(self.x * b, self.y * b, self.z * b)
54 end
55
56 function __div(b)
57 if b instanceof vector3 then
58 return new vector3(self.x / b.x, self.y / b.y, self.z / b.z)
59 end
60 return new vector3(self.x / b, self.y / b, self.z / b)
61 end
62
63 function __eq(b)
64 return self.x == b.x and self.y == b.y and self.z == b.z
65 end
66
67 function __len()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected