Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int GO_index(lua_State * L)
- {
- //Stack as expected [..., GO, key]
- lua_GameObject * go_lua = (lua_GameObject *)luaL_checkudata(L, -2, "__GameObject__");
- const char * key = lua_tostring(L, -1);
- std::string val = go_lua->go->getField(key);
- if (!val.empty())
- {
- lua_pushstring(L, val.c_str());
- }
- else
- {
- //See if the metatable has what they are asking for. (Like a method name)
- luaL_getmetatable(L, "__GameObject__"); //[complex_inst, key, Complex-metatable]
- //Make a copy of the key at the top of the stack
- lua_pushvalue(L, -2);
- //Gets the field from the table at index -2 using the key at the stack top
- lua_rawget(L, -2); //[complex_inst, key, Complex-metatable, nil/value]
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement