lua.cpp 531 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "Crown.h"
  2. #include "Game.h"
  3. namespace crown
  4. {
  5. lua_State* L;
  6. void init()
  7. {
  8. L = luaL_newstate();
  9. luaL_openlibs(L);
  10. if (luaL_loadfile(L, "/home/mikymod/test/res_linux/lua/game.raw") || lua_pcall(L, 0, 0, 0))
  11. {
  12. os::printf("error: %s", lua_tostring(L, -1));
  13. }
  14. lua_getglobal(L, "init");
  15. lua_pcall(L, 0, 0, 0);
  16. }
  17. void shutdown()
  18. {
  19. lua_getglobal(L, "shutdown");
  20. lua_pcall(L, 0, 0, 0);
  21. lua_close(L);
  22. }
  23. void frame(float dt)
  24. {
  25. lua_getglobal(L, "frame");
  26. lua_pushnumber(L, dt);
  27. lua_pcall(L, 1, 0, 0);
  28. }
  29. }