|
cazador Apprentice
Joined: 08 Dec 2005 Posts: 108
|
Posted: 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"); |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: 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.
|
|
|
|
cazador Apprentice
Joined: 08 Dec 2005 Posts: 108
|
Posted: 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? |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: 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.
|
|
|
|
|
|