#include "dl_lua.h" #define LUA_USE_APICHECK #include #include "dl_lua_register.h" #include "io/dl_file.h" namespace dl { LuaScript* g_lua; LuaScript::LuaScript() { L = luaL_newstate(); luaL_openlibs(L); lua_register_all(L); } LuaScript::~LuaScript() { lua_close(L); } bool LuaScript::DoFile(std::string_view path_name) { Buffer buf = File::GetBuffer(path_name); int ret = luaL_loadbuffer(L, (const char*)buf.data(), buf.size(), path_name.data()); if (ret) { log_err("lua 执行(加载)失败:[{}]:{}", path_name, lua_tostring(L, -1)); return false; } ret = lua_pcall(L, 0, 0, 0); if (ret) { log_err("lua 执行失败:[{}]:{}", path_name, lua_tostring(L, -1)); return false; } return true; } }