Skip to content

Question about native vector math #813

Answered by vegorov-rbx
bandaloo asked this question in Q&A
Discussion options

You must be logged in to vote

Runtime doesn't detect this type automatically.
Instead, you need to provide a constructor function that returns the vector value.

For example, when you have created a VM, you register a function to build a vector:


static int lua_vector(lua_State* L)
{
    double x = luaL_checknumber(L, 1);
    double y = luaL_checknumber(L, 2);
    double z = luaL_checknumber(L, 3);
    lua_pushvector(L, float(x), float(y), float(z));
    return 1;
}

// Somewhere after initialization
lua_pushcfunction(L, lua_vector, "vector");
lua_setglobal(L, "vector");

Optionally, in compilation options, you can specify:

lua_CompileOptions copts = defaultOptions();
copts.vectorCtor = "vector";

This will tell the co…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@bandaloo
Comment options

Answer selected by bandaloo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants