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; }
BOOL CLuamgr::LoadLuaScript() { SGDP::ISDDBSession* pDBSession = gsapi::GetDBMgr()->GetCfgDBSession(); if(NULL == pDBSession) { return FALSE; } SGDP::ISDDBRecordSet* pRes = NULL; UINT32 dwErrID = 0; string strErr; INT32 nRet = pDBSession->ExecuteSqlRs(GetPropTableSelectSql("luafile", "", "select Common1, Common2, Common3, Common4, Common5, Calculate, Activity from ").c_str(), &pRes, &dwErrID, &strErr); if(SDDB_HAS_RECORDSET != nRet) { SYS_CRITICAL(_SDT("[%s: %d]: has no data!"), MSG_MARK); return FALSE; } INT32 nStatus = 0; if(pRes->GetRecord()) { if((0 == nStatus) && (nStatus = m_oLuaState->DoString(pRes->GetFieldValueByName("Common1")))) {}; if((0 == nStatus) && (nStatus = m_oLuaState->DoString(pRes->GetFieldValueByName("Common2")))) {}; if((0 == nStatus) && (nStatus = m_oLuaState->DoString(pRes->GetFieldValueByName("Common3")))) {}; if((0 == nStatus) && (nStatus = m_oLuaState->DoString(pRes->GetFieldValueByName("Common4")))) {}; if((0 == nStatus) && (nStatus = m_oLuaState->DoString(pRes->GetFieldValueByName("Common5")))) {}; if((0 == nStatus) && (nStatus = m_oLuaState->DoString(pRes->GetFieldValueByName("Calculate")))) {}; if((0 == nStatus) && (nStatus = m_oLuaState->DoString(pRes->GetFieldValueByName("Activity")))) {}; } if(NULL != pRes) { pRes->Release(); pRes = NULL; } if(0 != nStatus) { LuaStackObject luaError = m_oLuaState->StackTop(); const char* pszErrorMsg = luaError.GetString(); SYS_CRITICAL(_SDT("[%s: %d]: require Calculate failed!"), MSG_MARK); return FALSE; } return TRUE; }
// LuaDumpGlobals(file, alphabetical, maxIndentLevel, writeAll) extern "C" int LS_LuaDumpGlobals(lua_State* L) { LuaStateOutFile file; LuaState* state = lua_State_To_LuaState(L); LuaStack args(state); LuaStackObject fileObj = args[1]; const char* fileName = NULL; if ( fileObj.IsUserData() ) { FILE* stdioFile = (FILE *)fileObj.GetUserData(); file.Assign( stdioFile ); } else if ( fileObj.IsString() ) { fileName = fileObj.GetString(); } LuaStackObject alphabeticalObj = args[2]; LuaStackObject maxIndentLevelObj = args[3]; LuaStackObject writeAllObj = args[4]; bool alphabetical = alphabeticalObj.IsBoolean() ? alphabeticalObj.GetBoolean() : true; unsigned int maxIndentLevel = maxIndentLevelObj.IsInteger() ? (unsigned int)maxIndentLevelObj.GetInteger() : 0xFFFFFFFF; bool writeAll = writeAllObj.IsBoolean() ? writeAllObj.GetBoolean() : false; unsigned int flags = (alphabetical ? LuaState::DUMP_ALPHABETICAL : 0) | (writeAll ? LuaState::DUMP_WRITEALL : 0); if (fileName) { state->DumpGlobals(fileName, flags, maxIndentLevel); } else { state->DumpGlobals(file, flags, maxIndentLevel); } return 0; }
// 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; }