I'm writing a material system for a game engine that I'm working where a Lua script is basically used as a config file for the material.
I'm storing values in a table, but for vector values (vec2, vec3, etc.) I am embedding a table inside the main table to hold the multiple values, like so:
material = {
color = {0.2, 0.3, 1}
}
I want to get the individual values of color, and this is what I've tried to get the first value:
lua_getglobal(L, "material");
if (!lua_istable(L, -1)) {return;};
lua_pushstring(L, "color");
lua_gettable(L, -2);
if (lua_istable(L, -1)) {
lua_rawgeti(L, -1, 0);
printf("%f\n", lua_tonumber(L, -1));
}
lua_pop(L, 1);
But it only ever prints 0.0, no matter the first value in the color table. What am I doing wrong?
The first index should be 1 and not 0.
lua_rawgeti(L, -1, 1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With