I have a C function mesh_create_default(float *verts, uint32_t sizeof_verts)
:
void *mesh_create_default(float *verts, uint32_t sizeof_verts) {
static void *mesh;
mesh = mesh_create();
mesh_data(mesh, verts, sizeof_verts);
...
return &mesh;
}
and a function for lua to use:
int Lmesh_create_default(lua_State *L) {
lua_pushinteger(L, (uint64_t)mesh_create_default(lua_touserdata(L, 1), lua_tointeger(L, 2)));
return 0;
}
I am passing the result of mesh as a a 64 bit integer (perhaps not the best solution, but it works fine). My problem is with the verts
argument. I don't know how I can pass a lua array into C. I have tried researching this, but I haven't found anything that solves this problem.
Say I have this lua code (just an example of what I want to do, not actual working code):
Verts = { -- an array of vertices, perhaps it needs to be somehow converted into a float * (I would prefer to convert it on the C side though, and keep my lua scripts as clean as possible)
0.0, 1.0, 0.0,
1.0, -1.0, 0.0,
-1.0, -1.0, 0.0,
}
function Ready()
Mesh = mesh_create_default(Verts, 4 * 3 * 3) -- or 8? Lua uses doubles (I think) but my code
-- requires floats, so that could be a bit of a
-- problem...
end
I apologise if this is an easily solvable question. My knowledge of lua is not that good (thus why I decided to use it for my game engine, to learn it).
EDIT: I need the entire array because I don't know how large the verts
array is. The other option is to just get the size of the array as well too though (although less ideal and probably slower)
EDIT 2: Actually I do have the size of the array -- the sizeof_verts variable. Because of this, I think that this question is a duplicate of the question posted by @larsks (Read Lua table from C).