Skip to content

Commit 6caba3f

Browse files
committed
- fix crash when using print
1 parent 8801f76 commit 6caba3f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

DriverNGHook/Delegates/LuaDelegate.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,22 +193,28 @@ namespace DriverNG
193193
}
194194

195195
// install our print function to the game
196-
sv["print"] = [](sol::variadic_args aArgs, sol::this_state aState)
196+
sv["print"] = [](sol::variadic_args args, sol::this_state aState)
197197
{
198198
std::ostringstream oss;
199199
sol::state_view s(aState);
200+
auto toString = s["tostring"];
200201

201-
for (auto it = aArgs.cbegin(); it != aArgs.cend(); ++it)
202+
MsgInfo("[Lua] ");
203+
204+
for (auto it = args.cbegin(); it != args.cend(); ++it)
202205
{
203-
if (it != aArgs.cbegin())
206+
if (it != args.cbegin())
204207
{
205208
oss << " ";
209+
MsgInfo(" ");
206210
}
207-
std::string str = s["tostring"]((*it).get<sol::object>());
211+
212+
std::string str = ((*it).get_type() == sol::type::string) ? (*it).get<std::string>() : toString((*it).get<sol::object>());
213+
214+
MsgInfo(str.c_str());
208215
oss << str;
209216
}
210-
211-
MsgInfo("[Lua] %s\n", oss.str().c_str());
217+
MsgInfo("\n");
212218

213219
if(Globals::g_pDebugTools)
214220
Globals::g_pDebugTools->LogGameToConsole(oss.str());

0 commit comments

Comments
 (0)