|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Sun Sep 16, 2007 12:22 am
[2.03] Return from a Lua Function |
I'm trying to figure out how to return a value from CMUD function that executes in Lua script.
To be clear, I've defined a function in CMUD, and specified it's script type to be Lua. It does everything I want but I want to have it return a value to the rest of CMUD like I would any other CMUD funtion. In zScript I know the command is "#RETURN" but I'm not sure what to use in Lua.
I've tried "zs.cmd.return", "return" but neither seems to work.
Anyone got any suggestions? Fang this means you. |
|
_________________ Asati di tempari! |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Sep 16, 2007 8:53 am |
It seems that the function and return commands haven't been added to Lua - compare print(zs.cmd.function) and print(zs.cmd.return) to print(zs.cmd.additem).
But if you're defining functions that use Lua scripts, why not use a real Lua function? |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Sun Sep 16, 2007 4:52 pm |
I am... but what I need is to return that result to cMUD. What I used to do with two CMUD functions coded in zScript, I'm now doing with one CMUD function code in Lua, but I need that return.
As an aside, I need to use a real Lua function to be able to return multiple values without doing anything hoaky.
Guess I'll be waiting on Zugg then. (Zugg if your reading this I hope your and Chiara are enjoying Yellowstone.) |
|
_________________ Asati di tempari! |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Sep 24, 2007 8:04 pm |
Confirmed but very weird. Lua should have access to *all* commands and functions in zScript. So I'm not sure why zs.return isn't working properly. Anyway, added this to the bug list.
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Fri Sep 28, 2007 7:50 pm |
Well, this one was a pain.
Turns out that there seems to be a problem with the Lua parser. Apparently "return" is a reserved word, and even when it is defined as a valid table value, doing something like:
zs.return(123)
will not parse. It always results in a Lua parser error about a expected. If I change "return" to "ret" then I can get it to work. So Lua is treating the string "return" as a special case somehow and is not allowing it with user-objects like "zs".
In the process of fixing this, I decided to just implement it the way that you would expect. That is, you just use the normal Lua "return" function. So, to return a value from a Lua CMUD function, just use "return" in v2.04. |
|
|
|
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Fri Sep 28, 2007 7:56 pm |
Zugg wrote: |
So, to return a value from a Lua CMUD function, just use "return" in v2.04. |
Use "return" outside of any Lua function or object method, I assume? (Not that I know anything about Lua, but otherwise you couldn't return from a function or object method to the main code?) |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Fri Sep 28, 2007 8:49 pm |
Yep, correct. It's just like the body of the CMUD function was the body of a Lua function.
|
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Sun Sep 30, 2007 4:23 am |
This works like a charm now.. .thanks Zugg.
|
|
_________________ Asati di tempari! |
|
|
|
|
|