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
cazador
Apprentice


Joined: 08 Dec 2005
Posts: 108

PostPosted: Sat Feb 02, 2008 6:25 pm   

lua function
 
If I want to create a lua function. How do I do that so that it is available from triggers that use lua?

For example a function that i would want would be function strsplit(delimiter, text)


In the trigger, I would want to be able to do
b=strsplit("%s","this is a string to be split");
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Sat Feb 02, 2008 8:16 pm   
 
Just create the function in a global variable. CMUD uses a single Lua environment, so global variables are common to all settings in all modules. So just create your function in the normal way.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
cazador
Apprentice


Joined: 08 Dec 2005
Posts: 108

PostPosted: Sat Feb 02, 2008 10:07 pm   
 
I tried doing that. I made a variable called ea2. The xml for it is as follows

<var name="ea2" id="67">function ea()
print("hello")
end</var>


Then from the lua command line i did ea() and I get the following
ea()

Stack trace:
[string "code"]:1:in main chunk"

Any clue what i am doing wrong?
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Sat Feb 02, 2008 10:45 pm   
 
You're storing your function in a CMUD variable is what's wrong. It's important that you understand the difference between a CMUD variable and a Lua variable. Your code creating your function ea isn't actually run when you put it in the variable - you need to have it execute at least once so that the ea Lua variable has the function in it. So put your code in an OnConnect even so that it runs when you start your session, and it should work fine.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
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