Document.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #include "precompiled.h"
  28. #include "Document.h"
  29. #include <Rocket/Core/ElementDocument.h>
  30. #include <Rocket/Core/Context.h>
  31. #include "Element.h"
  32. namespace Rocket {
  33. namespace Core {
  34. namespace Lua {
  35. template<> void ExtraInit<Document>(lua_State* L, int metatable_index)
  36. {
  37. //we will inherit from Element
  38. ExtraInit<Element>(L,metatable_index);
  39. LuaType<Element>::_regfunctions(L,metatable_index,metatable_index - 1);
  40. }
  41. //methods
  42. int DocumentPullToFront(lua_State* L, Document* obj)
  43. {
  44. obj->PullToFront();
  45. return 0;
  46. }
  47. int DocumentPushToBack(lua_State* L, Document* obj)
  48. {
  49. obj->PushToBack();
  50. return 0;
  51. }
  52. int DocumentShow(lua_State* L, Document* obj)
  53. {
  54. int top = lua_gettop(L);
  55. if(top == 0)
  56. obj->Show();
  57. else
  58. {
  59. int flag = luaL_checkinteger(L,1);
  60. obj->Show(flag);
  61. }
  62. return 0;
  63. }
  64. int DocumentHide(lua_State* L, Document* obj)
  65. {
  66. obj->Hide();
  67. return 0;
  68. }
  69. int DocumentClose(lua_State* L, Document* obj)
  70. {
  71. obj->Close();
  72. return 0;
  73. }
  74. int DocumentCreateElement(lua_State* L, Document* obj)
  75. {
  76. const char* tag = luaL_checkstring(L,1);
  77. Element* ele = obj->CreateElement(tag);
  78. LuaType<Element>::push(L,ele,false);
  79. return 1;
  80. }
  81. int DocumentCreateTextNode(lua_State* L, Document* obj)
  82. {
  83. //need ElementText object first
  84. const char* text = luaL_checkstring(L,1);
  85. ElementText* et = obj->CreateTextNode(text);
  86. LuaType<ElementText>::push(L, et, false);
  87. return 1;
  88. }
  89. //getters
  90. int DocumentGetAttrtitle(lua_State* L)
  91. {
  92. Document* doc = LuaType<Document>::check(L,1);
  93. LUACHECKOBJ(doc);
  94. lua_pushstring(L,doc->GetTitle().CString());
  95. return 1;
  96. }
  97. int DocumentGetAttrcontext(lua_State* L)
  98. {
  99. Document* doc = LuaType<Document>::check(L,1);
  100. LUACHECKOBJ(doc);
  101. LuaType<Context>::push(L,doc->GetContext(),false);
  102. return 1;
  103. }
  104. //setters
  105. int DocumentSetAttrtitle(lua_State* L)
  106. {
  107. Document* doc = LuaType<Document>::check(L,1);
  108. LUACHECKOBJ(doc);
  109. const char* title = luaL_checkstring(L,2);
  110. doc->SetTitle(title);
  111. return 0;
  112. }
  113. RegType<Document> DocumentMethods[] =
  114. {
  115. LUAMETHOD(Document,PullToFront)
  116. LUAMETHOD(Document,PushToBack)
  117. LUAMETHOD(Document,Show)
  118. LUAMETHOD(Document,Hide)
  119. LUAMETHOD(Document,Close)
  120. LUAMETHOD(Document,CreateElement)
  121. LUAMETHOD(Document,CreateTextNode)
  122. { NULL, NULL },
  123. };
  124. luaL_reg DocumentGetters[] =
  125. {
  126. LUAGETTER(Document,title)
  127. LUAGETTER(Document,context)
  128. { NULL, NULL },
  129. };
  130. luaL_reg DocumentSetters[] =
  131. {
  132. LUASETTER(Document,title)
  133. { NULL, NULL },
  134. };
  135. LUATYPEDEFINE(Document,true)
  136. }
  137. }
  138. }