Files
dnf-utils/sgutil/sgu_mode_run_lua_file.cpp
T
2025-09-02 22:45:41 +08:00

35 lines
643 B
C++

#include "sgu_mode_run_lua_file.h"
#include "sgu_lua_npk_file.h"
#include "sgu_lua_utils.h"
#include "libNPK.h"
extern "C"
{
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
};
#include "lua_tinker.h"
bool run_lua_file(const char* szLuaFilename)
{
lua_State* L = lua_open();
luaL_openlibs(L);
//register global functions
lua_tinker::def(L, "getLastErrorCode", &NPK::getLastErrorCode);
lua_tinker::def(L, "getLastErrorMessage", &NPK::getLastErrorMessage);
//register classes
registerNPKLuaLibs(L);
registerUtilsLuaLibs(L);
//run lua file
lua_tinker::dofile(L, szLuaFilename);
//cleanup
lua_close(L);
return true;
}