------------------------------------------------------------------------
| 260 | |
| 261 | //------------------------------------------------------------------------ |
| 262 | int CScriptBind_UIAction::CallFunction(IFunctionHandler* pH, const char* elementName, int instanceID, const char* functionName) |
| 263 | { |
| 264 | SUIArguments args; |
| 265 | if (!SUIToLuaConversationHelper::LuaArgsToUIArgs(pH, 4, args)) |
| 266 | { |
| 267 | UIACTION_WARNING("LUA: Failed to call function %s on element %s: Invalid arguments", functionName, elementName); |
| 268 | return pH->EndFunction(false); |
| 269 | } |
| 270 | |
| 271 | IUIElement* pElement = GetElement(elementName, instanceID, true); |
| 272 | if (pElement) |
| 273 | { |
| 274 | const SUIEventDesc* pFctDesc = pElement->GetFunctionDesc(functionName); |
| 275 | if (pFctDesc) |
| 276 | { |
| 277 | TUIData res; |
| 278 | bool bFctOk = true; |
| 279 | if (instanceID < 0) |
| 280 | { |
| 281 | IUIElementIteratorPtr elements = pElement->GetInstances(); |
| 282 | while (IUIElement* pInstance = elements->Next()) |
| 283 | bFctOk &= pInstance->CallFunction(pFctDesc, args, &res); |
| 284 | } |
| 285 | else |
| 286 | { |
| 287 | bFctOk = pElement->CallFunction(pFctDesc, args, &res); |
| 288 | } |
| 289 | if (bFctOk) |
| 290 | { |
| 291 | string sRes; |
| 292 | res.GetValueWithConversion(sRes); |
| 293 | return pH->EndFunction(sRes.c_str()); |
| 294 | } |
| 295 | } |
| 296 | UIACTION_WARNING("LUA: UIElement %s does not have function %s", elementName, functionName); |
| 297 | } |
| 298 | else if (IUIEventSystem* pEventSystem = GetEventSystem(elementName, IUIEventSystem::eEST_UI_TO_SYSTEM)) |
| 299 | { |
| 300 | uint eventid = pEventSystem->GetEventId(functionName); |
| 301 | if (eventid != ~0) |
| 302 | { |
| 303 | SUIArguments res = pEventSystem->SendEvent(SUIEvent(eventid, args)); |
| 304 | SmartScriptTable table = gEnv->pScriptSystem->CreateTable(); |
| 305 | SUIToLuaConversationHelper::UIArgsToLuaTable(res, table); |
| 306 | return pH->EndFunction(table); |
| 307 | } |
| 308 | UIACTION_WARNING("LUA: UIEventSystem %s does not have event %s", elementName, functionName); |
| 309 | } |
| 310 | else |
| 311 | { |
| 312 | UIACTION_WARNING("LUA: UIElement or UIEventSystem %s does not exist", elementName); |
| 313 | } |
| 314 | return pH->EndFunction(false); |
| 315 | } |
| 316 | |
| 317 | //------------------------------------------------------------------------ |
| 318 | int CScriptBind_UIAction::SetVariable(IFunctionHandler* pH, const char* elementName, int instanceID, const char* varName) |
nothing calls this directly
no test coverage detected