setup the meta-table for synched variables
| 380 | |
| 381 | // setup the meta-table for synched variables |
| 382 | bool CScriptRMI::BuildSynchTable(SmartScriptTable vars, SmartScriptTable cls, const char* name) |
| 383 | { |
| 384 | IScriptSystem* pSS = vars->GetScriptSystem(); |
| 385 | SmartScriptTable synched(pSS); |
| 386 | SmartScriptTable defaultValues(pSS); |
| 387 | |
| 388 | // TODO: Improve |
| 389 | IScriptTable::SUserFunctionDesc fd; |
| 390 | fd.pFunctor = functor_ret(SynchedNewIndexFunction); |
| 391 | fd.sFunctionName = "__newindex"; |
| 392 | fd.sGlobalName = "<net-dispatch>"; |
| 393 | fd.sFunctionParams = "(...)"; |
| 394 | synched->AddFunction(fd); |
| 395 | |
| 396 | std::vector<SSynchedPropertyInfo> properties; |
| 397 | |
| 398 | IScriptTable::Iterator iter = vars->BeginIteration(); |
| 399 | while (vars->MoveNext(iter)) |
| 400 | { |
| 401 | if (iter.sKey) |
| 402 | { |
| 403 | int type; |
| 404 | if (!vars->GetValue(iter.sKey, type)) |
| 405 | { |
| 406 | vars->EndIteration(iter); |
| 407 | pSS->RaiseError("No type for %s", iter.sKey); |
| 408 | return false; |
| 409 | } |
| 410 | size_t len = strlen(iter.sKey); |
| 411 | if (len > MaxSynchedPropertyNameLength) |
| 412 | { |
| 413 | vars->EndIteration(iter); |
| 414 | pSS->RaiseError("Synched var name '%s' too long (max is %d)", |
| 415 | iter.sKey, (int)MaxSynchedPropertyNameLength); |
| 416 | return false; |
| 417 | } |
| 418 | SSynchedPropertyInfo info; |
| 419 | cry_strcpy(info.name, iter.sKey); |
| 420 | info.type = (EScriptSerializeType) type; |
| 421 | properties.push_back(info); |
| 422 | |
| 423 | if (info.type == eSST_String) |
| 424 | defaultValues->SetValue(iter.sKey, ""); |
| 425 | else |
| 426 | defaultValues->SetValue(iter.sKey, 0); |
| 427 | } |
| 428 | } |
| 429 | vars->EndIteration(iter); |
| 430 | |
| 431 | if (properties.empty()) |
| 432 | return true; |
| 433 | |
| 434 | fd.pFunctor = NULL; |
| 435 | fd.pUserDataFunc = SerializeFunction; |
| 436 | fd.nDataSize = sizeof(SSynchedPropertyInfo) * properties.size(); |
| 437 | fd.pDataBuffer = &properties[0]; |
| 438 | fd.sFunctionName = SERIALIZE_FUNCTION; |
| 439 | fd.sFunctionParams = "(...)"; |
nothing calls this directly
no test coverage detected