Document.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include "precompiled.h"
  2. #include "Document.h"
  3. #include <Rocket/Core/ElementDocument.h>
  4. #include <Rocket/Core/Context.h>
  5. namespace Rocket {
  6. namespace Core {
  7. namespace Lua {
  8. //methods
  9. int DocumentPullToFront(lua_State* L, Document* obj)
  10. {
  11. obj->PullToFront();
  12. return 0;
  13. }
  14. int DocumentPushToBack(lua_State* L, Document* obj)
  15. {
  16. obj->PushToBack();
  17. return 0;
  18. }
  19. int DocumentShow(lua_State* L, Document* obj)
  20. {
  21. int top = lua_gettop(L);
  22. if(top == 0)
  23. obj->Show();
  24. else
  25. {
  26. int flag = luaL_checkinteger(L,1);
  27. obj->Show(flag);
  28. }
  29. return 0;
  30. }
  31. int DocumentHide(lua_State* L, Document* obj)
  32. {
  33. obj->Hide();
  34. return 0;
  35. }
  36. int DocumentClose(lua_State* L, Document* obj)
  37. {
  38. obj->Close();
  39. return 0;
  40. }
  41. int DocumentCreateElement(lua_State* L, Document* obj)
  42. {
  43. const char* tag = luaL_checkstring(L,1);
  44. Element* ele = obj->CreateElement(tag);
  45. LuaType<Element>::push(L,ele,false);
  46. return 1;
  47. }
  48. int DocumentCreateTextNode(lua_State* L, Document* obj)
  49. {
  50. //need ElementText object first
  51. return 0;
  52. }
  53. //getters
  54. int DocumentGetAttrtitle(lua_State* L)
  55. {
  56. Document* doc = LuaType<Document>::check(L,1);
  57. LUACHECKOBJ(doc);
  58. lua_pushstring(L,doc->GetTitle().CString());
  59. return 1;
  60. }
  61. int DocumentGetAttrcontext(lua_State* L)
  62. {
  63. Document* doc = LuaType<Document>::check(L,1);
  64. LUACHECKOBJ(doc);
  65. LuaType<Context>::push(L,doc->GetContext(),false);
  66. return 1;
  67. }
  68. //setters
  69. int DocumentSetAttrtitle(lua_State* L)
  70. {
  71. Document* doc = LuaType<Document>::check(L,1);
  72. LUACHECKOBJ(doc);
  73. const char* title = luaL_checkstring(L,2);
  74. doc->SetTitle(title);
  75. return 0;
  76. }
  77. RegType<Document> DocumentMethods[] =
  78. {
  79. LUAMETHOD(Document,PullToFront)
  80. LUAMETHOD(Document,PushToBack)
  81. LUAMETHOD(Document,Show)
  82. LUAMETHOD(Document,Hide)
  83. LUAMETHOD(Document,Close)
  84. LUAMETHOD(Document,CreateElement)
  85. LUAMETHOD(Document,CreateTextNode)
  86. { NULL, NULL },
  87. };
  88. luaL_reg DocumentGetters[] =
  89. {
  90. LUAGETTER(Document,title)
  91. LUAGETTER(Document,context)
  92. { NULL, NULL },
  93. };
  94. luaL_reg DocumentSetters[] =
  95. {
  96. LUASETTER(Document,title)
  97. { NULL, NULL },
  98. };
  99. /*
  100. template<> const char* GetTClassName<Document>() { return "Document"; }
  101. template<> RegType<Document>* GetMethodTable<Document>() { return DocumentMethods; }
  102. template<> luaL_reg* GetAttrTable<Document>() { return DocumentGetters; }
  103. template<> luaL_reg* SetAttrTable<Document>() { return DocumentSetters; }
  104. */
  105. }
  106. }
  107. }