On 14/07/2025 15:35, Mokka Chocolata wrote:
> I'm making a custom Vector3 class, where there is a new function. I'm
> making this for a game (this is not Roblox, rather a completely
> different engine).
>
> When I call the function, it returns the X value. I want a table with
> XYZ and special metafunctions to handle math.
Looks like LuaLibs_Vec3ToLuaVector3 is returning just one table to the
stack, but LuaLibs_Vector3New is returning 2 which means that last stack
argument passed to it plus the new table.
I suspect the following will work, but shows what needs changing:
local a, b = Vector3.new(0.1, 0.2, 0.3) -- a = 0.3
print(b) -- the new vector
You can also improve things by only defining the metatable once
(probably in SetupLibs) and reusing it. Read up on luaL_newmetatable and
luaL_getmetatable.
A few other things need fixing up there to make it a good module, but
that'll get you working for now.
Scott