project-navigation
Personal tools

Author Topic: extension to ui script language  (Read 5722 times)

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
extension to ui script language
« on: June 01, 2014, 04:58:12 pm »
Hi,

I've been working on some modifications to the ui script language. I've added implementation for a
Code: [Select]
forchildin keyword (a foreach that iterates child nodes of a given ui-node) and the
Code: [Select]
break statement to exit a loop. Now the code needs a last finishing touch. Inside the iterating body I need a way to reference the child node being visited. To do so, I guess I have to change the executing context of the action and add a hidden variable (something like self) that can be referenced from the code body of the iterating block. I cannot seem to figure out how to do this? Any help is appreciated.

Regards,
xray

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: extension to ui script language
« Reply #1 on: June 01, 2014, 07:39:51 pm »
please pastebin your patch - then it's a lot easier to help you

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: extension to ui script language
« Reply #2 on: June 01, 2014, 08:44:15 pm »
Hi Mattn,

Ah yes, sorry. I should have thought about that. The code below is from the file ui_actions.cpp.
Code: [Select]
/*
expected usage in .ufo scripts:

forchildin ( panel ) {
}
*/
case EA_FORCHILDIN:
{
uiNode_t* root;
root = UI_GetNodeFromExpression(action->d.nonTerminal.left, context, nullptr);

uiNode_t* node = root->firstChild;
int loop = 0;
while (node != root->lastChild) {
UI_ExecuteActions(action->d.nonTerminal.right, context);
if (context->breakLoop) {
context->breakLoop = false;
break;
}
if (loop > 1000) {
Com_Printf("UI_ExecuteAction: Infinite loop. Force breaking 'forchildin'\n");
break;
}
node = node->next;
loop++;
}
break;
}

Somewhere in the while loop, before UI_ExecuteActions(..) I have to create a variable that can be accessed from within the script that references the current value of
Code: [Select]
node. The attached 7z contains the modified files.

Regards,
xray