Skip to content

Commit

Permalink
lua fix
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij committed May 16, 2020
1 parent 8b358ea commit bfa02e5
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion WickedEngine/wiLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,31 @@ int Internal_DoFile(lua_State* L)
if (argc > 0)
{
std::string filename = wiLua::SGetString(L, 1);
wiLua::GetGlobal()->RunFile(filename);
std::vector<uint8_t> filedata;
if (wiHelper::FileRead(filename, filedata))
{
std::string command = string(filedata.begin(), filedata.end());
int status = luaL_loadstring(L, command.c_str());
if (status == 0)
{
status = lua_pcall(L, 0, LUA_MULTRET, 0);
}

if (status != 0)
{
const char* str = lua_tostring(L, -1);

if (str == nullptr)
return 0;

stringstream ss("");
ss << WILUA_ERROR_PREFIX << str;
wiBackLog::post(ss.str().c_str());
ss << endl;
OutputDebugStringA(ss.str().c_str());
lua_pop(L, 1); // remove error message
}
}
}
else
{
Expand Down

0 comments on commit bfa02e5

Please sign in to comment.