#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.open_libraries( sol::lib::base, sol::lib::string, sol::lib::math, sol::lib::package); } LuaScript::~LuaScript() { } bool LuaScript::DoString(std::string_view str) { try { auto ret = _l.script(str); } catch (sol::error& e) { log_warn("{}\n{}", e.what(), str); return false; } return true; } bool LuaScript::DoFile(std::string_view path_name) { try { std::string str = File::GetString(path_name); auto ret = _l.script(str, std::string{ path_name }); } catch (sol::error& e) { log_warn("{}", e.what()); return false; } return true; } bool LuaScript::ExcuteFunction(sol::function func) { if (!func) return false; sol::function_result ret = func(); if (!ret.valid()) { sol::error e = ret; log_warn("{}", e.what()); return false; } return true; } void LuaScript::RegisterAll() { lua_register_all(_l); } }