| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #include <iostream>
- #include "Crown.h"
- #include "lua.hpp"
- #include <unistd.h>
- using namespace crown;
- static void report_errors(lua_State* state, const int status)
- {
- if (status != 0)
- {
- std::cerr << "-- " << lua_tostring(state, -1) << std::endl;
- lua_pop(state, 1);
- }
- }
- int main(int argc, char** argv)
- {
- lua_State* lua_state;
- Filesystem fs("/home/mikymod/test/res_compiled");
- FileResourceArchive archive(fs);
- MallocAllocator allocator;
- ResourceManager res_manager(archive, allocator);
- ResourceId script = res_manager.load("lua/hello.lua");
- while (1)
- {
- res_manager.flush_load_queue();
- res_manager.bring_loaded_online();
- if (res_manager.is_loaded(script))
- {
- lua_state = luaL_newstate();
- luaL_openlibs(lua_state);
- assert(res_manager.data(script) != NULL);
- ScriptResource* resource = (ScriptResource*)res_manager.data(script);
- int s = luaL_loadbuffer(lua_state, (char*)resource->data(), 47, "");
- if (s == 0)
- {
- s = lua_pcall(lua_state, 0, LUA_MULTRET, 0);
- }
- report_errors(lua_state, s);
- break;
- }
- }
- lua_close(lua_state);
- return 0;
- }
|