CString MakeValueTextFromObject(LuaStackObject value) { CString valueStr; if (value.IsNumber()) { valueStr.Format(_T("%f"), value.GetNumber()); } else if (value.IsString()) { valueStr = value.GetString(); if (valueStr == "!!!NIL!!!") valueStr = _T("nil"); else if (valueStr == "!!!USERDATA!!!") valueStr = _T("[userdata]"); else if (valueStr == "!!!FUNCTION!!!") valueStr = _T("[function]"); else if (valueStr == "!!!FUNCTION!!!") valueStr = _T("[cfunction]"); else valueStr = _T("\"") + valueStr + _T("\""); } else if (value.IsTable()) { valueStr = _T("[table]"); } return valueStr; }
// LuaDumpObject(file, key, value, alphabetical, indentLevel, maxIndentLevel, writeAll) extern "C" int LS_LuaDumpObject( lua_State* L ) { LuaStateOutFile file; LuaState* state = lua_State_To_LuaState(L); LuaStack args(state); LuaStackObject fileObj = args[1]; if (fileObj.IsTable() && state->GetTop() == 1) { LuaObject valueObj(fileObj); LuaObject nameObj; LuaStateOutString stringFile; state->DumpObject(stringFile, NULL, valueObj, LuaState::DUMP_ALPHABETICAL, 0, -1); state->PushString(stringFile.GetBuffer()); return 1; } const char* fileName = NULL; if ( fileObj.IsUserData() ) { FILE* stdioFile = (FILE *)fileObj.GetUserData(); file.Assign( stdioFile ); } else if ( fileObj.IsString() ) { fileName = fileObj.GetString(); } LuaObject nameObj = args[2]; LuaObject valueObj = args[3]; LuaStackObject alphabeticalObj = args[4]; LuaStackObject indentLevelObj = args[5]; LuaStackObject maxIndentLevelObj = args[6]; LuaStackObject writeAllObj = args[7]; bool writeAll = writeAllObj.IsBoolean() ? writeAllObj.GetBoolean() : false; bool alphabetical = alphabeticalObj.IsBoolean() ? alphabeticalObj.GetBoolean() : true; unsigned int maxIndentLevel = maxIndentLevelObj.IsInteger() ? (unsigned int)maxIndentLevelObj.GetInteger() : 0xFFFFFFFF; unsigned int flags = (alphabetical ? LuaState::DUMP_ALPHABETICAL : 0) | (writeAll ? LuaState::DUMP_WRITEALL : 0); if (fileName) { if (strcmp(fileName, ":string") == 0) { LuaStateOutString stringFile; state->DumpObject(stringFile, nameObj, valueObj, flags, indentLevelObj.GetInteger(), maxIndentLevel); state->PushString(stringFile.GetBuffer()); return 1; } else { state->DumpObject(fileName, nameObj, valueObj, flags, (unsigned int)indentLevelObj.GetInteger(), maxIndentLevel); } } else { state->DumpObject(file, nameObj, valueObj, flags, (unsigned int)indentLevelObj.GetInteger(), maxIndentLevel); } return 0; }