lua.cpp 595 B

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