Rocket.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "precompiled.h"
  2. #include "Rocket.h"
  3. #include <Rocket/Core/Core.h>
  4. namespace Rocket {
  5. namespace Core {
  6. namespace Lua {
  7. template<> void LuaType<rocket>::extra_init(lua_State* L, int metatable_index)
  8. {
  9. //because of the way LuaType::Register is done, we know that the methods table is directly
  10. //before the metatable
  11. int method_index = metatable_index - 1;
  12. lua_pushcfunction(L,rocketCreateContext);
  13. lua_setfield(L,method_index,"CreateContext");
  14. lua_pushcfunction(L,rocketLoadFontFace);
  15. lua_setfield(L,method_index,"LoadFontFace");
  16. lua_pushcfunction(L,rocketRegisterTag);
  17. lua_setfield(L,method_index,"RegisterTag");
  18. return;
  19. }
  20. int rocketCreateContext(lua_State* L)
  21. {
  22. const char* name = luaL_checkstring(L,1);
  23. Vector2i* dimensions = LuaType<Vector2i>::check(L,2);
  24. Context* new_context = CreateContext(name, *dimensions);
  25. if(new_context == NULL || dimensions == NULL)
  26. {
  27. lua_pushnil(L);
  28. return 1;
  29. }
  30. else
  31. {
  32. LuaType<Context>::push(L, new_context);
  33. return 1;
  34. }
  35. }
  36. int rocketLoadFontFace(lua_State* L)
  37. {
  38. const char* file = luaL_checkstring(L,1);
  39. FontDatabase::LoadFontFace(file);
  40. return 0;
  41. }
  42. int rocketRegisterTag(lua_State* L)
  43. {
  44. return 0;
  45. }
  46. int rocketGetAttrcontexts(lua_State* L)
  47. {
  48. return 0;
  49. }
  50. RegType<rocket> rocketMethods[] =
  51. {
  52. { NULL, NULL },
  53. };
  54. luaL_reg rocketGetters[] =
  55. {
  56. LUAGETTER(rocket,contexts)
  57. { NULL, NULL },
  58. };
  59. luaL_reg rocketSetters[] =
  60. {
  61. { NULL, NULL },
  62. };
  63. template<> const char* GetTClassName<rocket>() { return "rocket"; }
  64. template<> RegType<rocket>* GetMethodTable<rocket>() { return rocketMethods; }
  65. template<> luaL_reg* GetAttrTable<rocket>() { return rocketGetters; }
  66. template<> luaL_reg* SetAttrTable<rocket>() { return rocketSetters; }
  67. }
  68. }
  69. }