lua_wrappers.h 668 B

12345678910111213141516171819202122232425262728293031323334
  1. #pragma once
  2. extern "C" {
  3. #include <stdio.h>
  4. #include "lua.h"
  5. #include "lualib.h"
  6. #include "lauxlib.h"
  7. }
  8. %HEADERS%
  9. using namespace std;
  10. namespace Polycode {
  11. class LuaEventHandler : public EventHandler {
  12. public:
  13. LuaEventHandler() : EventHandler() {}
  14. void handleEvent(Event *e) {
  15. lua_getglobal(L, "__customError");
  16. int errH = lua_gettop(L);
  17. lua_getglobal(L, "__handleEvent");
  18. lua_rawgeti( L, LUA_REGISTRYINDEX, wrapperIndex );
  19. PolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));
  20. *userdataPtr = (PolyBase*)e;
  21. lua_pcall(L, 2, 0, errH);
  22. lua_settop(L, 0);
  23. }
  24. int wrapperIndex;
  25. lua_State *L;
  26. };
  27. %BODY%
  28. }