ElementInstancer.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "ElementInstancer.h"
  2. namespace Rml {
  3. namespace Lua {
  4. template <>
  5. void ExtraInit<ElementInstancer>(lua_State* L, int metatable_index)
  6. {
  7. lua_pushcfunction(L, ElementInstancernew);
  8. lua_setfield(L, metatable_index - 1, "new");
  9. }
  10. // method
  11. int ElementInstancernew(lua_State* L)
  12. {
  13. LuaElementInstancer* lei = new LuaElementInstancer(L);
  14. LuaType<ElementInstancer>::push(L, lei, true);
  15. return 1;
  16. }
  17. // setter
  18. int ElementInstancerSetAttrInstanceElement(lua_State* L)
  19. {
  20. LuaElementInstancer* lei = (LuaElementInstancer*)LuaType<ElementInstancer>::check(L, 1);
  21. RMLUI_CHECK_OBJ(lei);
  22. if (lua_type(L, 2) != LUA_TFUNCTION)
  23. {
  24. Log::Message(Log::LT_ERROR, "The argument to ElementInstancer.InstanceElement must be a function. You passed in a %s.", luaL_typename(L, 2));
  25. return 0;
  26. }
  27. lei->PushFunctionsTable(L); // top of the stack is now ELEMENTINSTANCERFUNCTIONS table
  28. lua_pushvalue(L, 2); // copy of the function
  29. lei->ref_InstanceElement = luaL_ref(L, -2);
  30. lua_pop(L, 1); // pop the ELEMENTINSTANCERFUNCTIONS table
  31. return 0;
  32. }
  33. RegType<ElementInstancer> ElementInstancerMethods[] = {
  34. {nullptr, nullptr},
  35. };
  36. luaL_Reg ElementInstancerGetters[] = {
  37. {nullptr, nullptr},
  38. };
  39. luaL_Reg ElementInstancerSetters[] = {
  40. RMLUI_LUASETTER(ElementInstancer, InstanceElement),
  41. {nullptr, nullptr},
  42. };
  43. RMLUI_LUATYPE_DEFINE(ElementInstancer)
  44. } // namespace Lua
  45. } // namespace Rml