Document.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. lua_pushstring(L,doc->GetTitle().CString());
  58. return 1;
  59. }
  60. int DocumentGetAttrcontext(lua_State* L)
  61. {
  62. Document* doc = LuaType<Document>::check(L,1);
  63. LuaType<Context>::push(L,doc->GetContext(),false);
  64. return 1;
  65. }
  66. //setters
  67. int DocumentSetAttrtitle(lua_State* L)
  68. {
  69. Document* doc = LuaType<Document>::check(L,1);
  70. const char* title = luaL_checkstring(L,2);
  71. doc->SetTitle(title);
  72. return 0;
  73. }
  74. RegType<Document> DocumentMethods[] =
  75. {
  76. LUAMETHOD(Document,PullToFront)
  77. LUAMETHOD(Document,PushToBack)
  78. LUAMETHOD(Document,Show)
  79. LUAMETHOD(Document,Hide)
  80. LUAMETHOD(Document,Close)
  81. LUAMETHOD(Document,CreateElement)
  82. LUAMETHOD(Document,CreateTextNode)
  83. { NULL, NULL },
  84. };
  85. luaL_reg DocumentGetters[] =
  86. {
  87. LUAGETTER(Document,title)
  88. LUAGETTER(Document,context)
  89. { NULL, NULL },
  90. };
  91. luaL_reg DocumentSetters[] =
  92. {
  93. LUASETTER(Document,title)
  94. { NULL, NULL },
  95. };
  96. /*
  97. template<> const char* GetTClassName<Document>() { return "Document"; }
  98. template<> RegType<Document>* GetMethodTable<Document>() { return DocumentMethods; }
  99. template<> luaL_reg* GetAttrTable<Document>() { return DocumentGetters; }
  100. template<> luaL_reg* SetAttrTable<Document>() { return DocumentSetters; }
  101. */
  102. }
  103. }
  104. }