ContextDocumentsProxy.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "precompiled.h"
  2. #include "ContextDocumentsProxy.h"
  3. #include <Rocket/Core/ElementDocument.h>
  4. namespace Rocket {
  5. namespace Core {
  6. namespace Lua {
  7. typedef Rocket::Core::ElementDocument Document;
  8. int ContextDocumentsProxy__index(lua_State* L)
  9. {
  10. /*the table obj and the missing key are currently on the stack(index 1 & 2) as defined by the Lua language*/
  11. int type = lua_type(L,2);
  12. if(type == LUA_TNUMBER || type == LUA_TSTRING) //only valid key types
  13. {
  14. ContextDocumentsProxy* proxy = LuaType<ContextDocumentsProxy>::check(L,1);
  15. Document* ret = NULL;
  16. if(type == LUA_TSTRING)
  17. ret = proxy->owner->GetDocument(luaL_checkstring(L,2));
  18. else
  19. ret = proxy->owner->GetDocument(luaL_checkint(L,2));
  20. LuaType<Document>::push(L,ret,false);
  21. return 1;
  22. }
  23. else
  24. return LuaType<ContextDocumentsProxy>::index(L);
  25. }
  26. //method
  27. int ContextDocumentsProxyGetTable(lua_State* L, ContextDocumentsProxy* obj)
  28. {
  29. Context* cont = obj->owner;
  30. Element* root = cont->GetRootElement();
  31. lua_newtable(L);
  32. int tableindex = lua_gettop(L);
  33. for(int i = 0; i < root->GetNumChildren(); i++)
  34. {
  35. Document* doc = root->GetChild(i)->GetOwnerDocument();
  36. if(doc == NULL)
  37. continue;
  38. LuaType<Document>::push(L,doc);
  39. lua_pushvalue(L,-1); //put it on the stack twice, since we assign it to
  40. //both a string and integer index
  41. lua_setfield(L, tableindex,doc->GetId().CString());
  42. lua_rawseti(L,tableindex,i);
  43. }
  44. lua_settop(L,tableindex); //to make sure
  45. return 1;
  46. }
  47. RegType<ContextDocumentsProxy> ContextDocumentsProxyMethods[] =
  48. {
  49. LUAMETHOD(ContextDocumentsProxy,GetTable)
  50. { NULL, NULL },
  51. };
  52. luaL_reg ContextDocumentsProxyGetters[] =
  53. {
  54. { NULL, NULL },
  55. };
  56. luaL_reg ContextDocumentsProxySetters[] =
  57. {
  58. { NULL, NULL },
  59. };
  60. }
  61. }
  62. }