Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Arde
Enchanter


Joined: 09 Sep 2007
Posts: 605

PostPosted: 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?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Arde
Enchanter


Joined: 09 Sep 2007
Posts: 605

PostPosted: 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?)
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: 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?
Reply with quote
Arde
Enchanter


Joined: 09 Sep 2007
Posts: 605

PostPosted: 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
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: 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!
Reply with quote
Arde
Enchanter


Joined: 09 Sep 2007
Posts: 605

PostPosted: 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
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net