|
Arde Enchanter
Joined: 09 Sep 2007 Posts: 605
|
Posted: Thu Jan 22, 2009 9:43 am
Howto: passing a stringlist to a Lua function |
What is the best way for passing a stringlist\database record to a Lua function? Say, for a list of 500 entries?
The obvious way is #FORALL @stringList {#LUA {luaFunc(%i)}}
What other ways are and what about their efficiency? |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Jan 22, 2009 11:45 am |
Depends how you're storing stuff and why - if you're going to be using Lua, it might be more sensible to use a Lua table and not use a stringlist at all.
|
|
|
|
Arde Enchanter
Joined: 09 Sep 2007 Posts: 605
|
Posted: Thu Jan 22, 2009 12:03 pm |
It is a stringlist used in trigger pattern, so it will be CMUD variable 100%. And the function is in Lua. I can feed it with values one after another with #FORALL (current implementation) or move this work inside that or another Lua function (how? And is the result worth all the efforts?)
|
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Thu Jan 22, 2009 4:05 pm |
Can't you just use zs.var.varname?
You can refer to that stringlist and use it in a function easily.
Example, I have a stringlist of like 600 city enemies.
If I want to print them all, I could just do:
Code: |
for _, v in ipairs(zs.var.cityEnemies) do
print(v)
end
|
If I do print(zs.var.cityEnemies) it displays it as a table array, so just do like you would any other array right? |
|
|
|
Arde Enchanter
Joined: 09 Sep 2007 Posts: 605
|
Posted: Thu Jan 22, 2009 7:18 pm |
oldguy2
Yes, I can. I haven't thought of this way.
And what if there are several variables with the same name but in the different classes? How zs.var will distinguish them? |
|
_________________ My personal bug|wish list:
-Wrong Priority when copy-paste setting
-1 prompt trigger for Mapper, Session and General Options, not 3 different!
-#SECTION can terminate threads
-Buttons can't start threads |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Jan 22, 2009 10:44 pm |
You know, that's a good point - I don't think it's possible to go down the tree from a class to its contents, only up the tree from the contents to the class. You can ascertain which variable you've got by looking at its class property, which is the class object of its parent class. But if it turns out you have the wrong one, I don't think there's any way to make Lua look for the other variable instead.
|
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Thu Jan 22, 2009 10:55 pm |
This should do what you want. zs.var["ClassName/VarName"]
Edit: I checked, the above will work. |
|
_________________ Asati di tempari! |
|
|
|
Arde Enchanter
Joined: 09 Sep 2007 Posts: 605
|
Posted: Fri Jan 23, 2009 8:38 am |
Thanks for the answers!
|
|
_________________ My personal bug|wish list:
-Wrong Priority when copy-paste setting
-1 prompt trigger for Mapper, Session and General Options, not 3 different!
-#SECTION can terminate threads
-Buttons can't start threads |
|
|
|
|
|