Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. int GO_index(lua_State * L)
  2. {
  3.     //Stack as expected                                                     [..., GO, key]
  4.     lua_GameObject * go_lua = (lua_GameObject *)luaL_checkudata(L, -2, "__GameObject__");
  5.     const char * key = lua_tostring(L, -1);
  6.     std::string val = go_lua->go->getField(key);
  7.     if (!val.empty())
  8.     {
  9.         lua_pushstring(L, val.c_str());
  10.     }
  11.     else
  12.     {
  13.         //See if the metatable has what they are asking for. (Like a method name)
  14.         luaL_getmetatable(L, "__GameObject__");                                 //[complex_inst, key, Complex-metatable]
  15.                                                                                 //Make a copy of the key at the top of the stack
  16.         lua_pushvalue(L, -2);
  17.         //Gets the field from the table at index -2 using the key at the stack top
  18.         lua_rawget(L, -2);                                                      //[complex_inst, key, Complex-metatable, nil/value]
  19.     }
  20.     return 1;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement