MCPcopy Create free account
hub / github.com/OGSR/OGSR-Engine / LogVariable

Method LogVariable

ogsr_engine/COMMON_AI/script_engine.cpp:418–490  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

416}
417
418void CScriptEngine::LogVariable(lua_State* l, const char* name, int level)
419{
420 const char* type;
421 int ntype = lua_type(l, -1);
422 type = lua_typename(l, ntype);
423
424 auto tabBuffer = std::make_unique<char[]>(level + 1);
425 memset(tabBuffer.get(), '\t', level);
426
427 char value[128];
428
429 switch (ntype)
430 {
431 case LUA_TFUNCTION: xr_strcpy(value, "[[function]]"); break;
432
433 case LUA_TTHREAD: xr_strcpy(value, "[[thread]]"); break;
434
435 case LUA_TNUMBER: xr_sprintf(value, "%f", lua_tonumber(l, -1)); break;
436
437 case LUA_TBOOLEAN: xr_sprintf(value, "%s", lua_toboolean(l, -1) ? "true" : "false"); break;
438
439 case LUA_TSTRING: xr_sprintf(value, "%.127s", lua_tostring(l, -1)); break;
440
441 case LUA_TTABLE:
442 if (level <= 3)
443 {
444 Msg("%s Table: %s", tabBuffer.get(), name);
445 LogTable(l, name, level + 1);
446 return;
447 }
448 else
449 {
450 xr_sprintf(value, "[...]");
451 }
452 break;
453
454 case LUA_TUSERDATA: {
455 auto obj = static_cast<luabind::detail::object_rep*>(lua_touserdata(l, -1));
456
457 // Skip already dumped object
458 if (m_dumpedObjList.find(obj) != m_dumpedObjList.end())
459 return;
460 m_dumpedObjList.insert(obj);
461
462 auto& r = obj->get_lua_table();
463 if (r.is_valid())
464 {
465 r.get(l);
466 Msg("%s Userdata: %s", tabBuffer.get(), name);
467 LogTable(l, name, level + 1);
468 lua_pop(l, 1); // Remove userobject
469 return;
470 }
471 else
472 {
473 // Dump class and element pointer if available
474 if (const auto objectClass = obj->crep())
475 {

Callers

nothing calls this directly

Calls 13

MsgFunction · 0.85
typeMethod · 0.80
lua_typeFunction · 0.50
lua_typenameFunction · 0.50
lua_tonumberFunction · 0.50
lua_tobooleanFunction · 0.50
lua_touserdataFunction · 0.50
getMethod · 0.45
findMethod · 0.45
endMethod · 0.45
insertMethod · 0.45
is_validMethod · 0.45

Tested by

no test coverage detected