overlay.d 767 B

1234567891011121314151617181920212223242526272829303132333435
  1. module scripts.lua.overlay;
  2. import system.debugwriteln;
  3. import system.overlay;
  4. import bindbc.lua;
  5. import core.sys.posix.sys.mman;
  6. import std.conv;
  7. import variables;
  8. void function() overlayInit;
  9. extern (C) nothrow int luaL_loadOverlay(lua_State *L) {
  10. try {
  11. code = loadOverlay(to!string(luaL_checkstring(L, 1)), &size);
  12. if (code is null) return 1;
  13. overlayInit = cast(void function())code;
  14. } catch (Exception e) {
  15. debugWriteln(e.msg);
  16. }
  17. return 0;
  18. }
  19. extern (C) nothrow int luaL_unloadOverlay(lua_State *L) {
  20. munmap(code, size);
  21. return 0;
  22. }
  23. extern (C) nothrow int luaL_runOverlay(lua_State *L) {
  24. try {
  25. overlayInit();
  26. } catch (Exception e) {
  27. debugWriteln(e.msg);
  28. }
  29. return 0;
  30. }