 |
wrym Magician
Joined: 06 Jul 2007 Posts: 349 Location: The big palace, My own lil world
|
Posted: Mon Apr 27, 2009 2:30 pm
[3.06] LUA zs.execfunc |
| Code: |
<func name="test" language="Lua" id="8">
<value>print(zs.param(1))
print(zs.param(2))
print(zs.param(3))
return "bugggy?"</value>
</func>
<alias name="test" id="9">
<value>#print test
#lua {print(zs.execfunc("test","first" , "second" ))}
#print {second test}
#lua {print(zs.execfunc("test", first , second, third))}
</value>
</alias> |
Paste into untitled session xml, execute test alias.
Executing Zscript functions from lua with parameters doesn't seem to pass the variables onto the function.
Can anyone confirm this? |
|
|
|
 |
Arde Enchanter
Joined: 09 Sep 2007 Posts: 605
|
Posted: Mon Apr 27, 2009 4:47 pm |
Your function doesn't compile.
|
|
_________________ 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 |
|
|
 |
wrym Magician
Joined: 06 Jul 2007 Posts: 349 Location: The big palace, My own lil world
|
Posted: Mon Apr 27, 2009 5:04 pm |
I just imported into a blank session and it compiles fine for me
| Code: |
| #print @test(one,two,three) |
Results in:
| Code: |
one
two
three
bugggy? |
However, ctrl+k does throw up a bogus error message, invalid token zs.param(1) at row 1 col 6 |
|
|
|
 |
Arde Enchanter
Joined: 09 Sep 2007 Posts: 605
|
Posted: Mon Apr 27, 2009 5:20 pm |
***deleted***
Sorry, your function is in Lua... Then it is OK |
|
Last edited by Arde on Mon Apr 27, 2009 5:26 pm; edited 1 time in total |
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Apr 27, 2009 5:25 pm |
The Ctrl-K syntax check can only check zScript syntax...not any other language. Just like clicking the Compiled Code tab for the test function doesn't show any compiled code (again, because that is only for zScript). There isn't any way for CMUD to syntax check other scripting languages and give any useful error messages. You can only get syntax error messages from Lua when you try to run a script.
In any case, running the "test" *alias* (not the test *function*) does reproduce the problem on my system here. it displays:
| Code: |
nil
nil
nil
buggy?
second test
nil
nil
nil
buggy? |
Looks like the problem is with the execfunc function in the Lua API. It isn't putting the arguments on the proper stack level that the zs.param function is looking for them. So I've added this to the bug list. |
|
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Apr 27, 2009 5:39 pm |
Is there any particular reason why you're using a CMUD function with Lua code rather than a native Lua function? If I was going to do this, I'd have a lua function... end defining my function to print parameters. Then I can call that from Lua with impunity, using lua variables and anything else I want, without having to cross over from Lua to CMUD and back again.
If I ever wanted to call my Lua code from zScript, I'd just create a CMUD function that does nothing but call the Lua function. My code would look something like this:
| Code: |
<func name="test" language="Lua">
<value>DoTest(zs.param(1),zs.param(2),zs.param(3)</value>
</func>
<event event="onConnect" language="Lua">
<value>if not DoTest then
function DoTest (one,two,three)
print(one)
print(two)
print(three)
return "bugggy?"
end
end</value>
</event> |
I promise that one of these days I'll finish my Lua tutorial! |
|
|
|
 |
Arde Enchanter
Joined: 09 Sep 2007 Posts: 605
|
Posted: Mon Apr 27, 2009 5:41 pm |
I've just checked my package with several functions written in Lua - functions and aliases which use zs.param do not work.
Even this (it worked in 3.05)
| Code: |
<func name="sharedChars" type="Integer" language="Lua" id="4">
<value>return strSharedChars(zs.param(1), zs.param(2))</value>
<arglist>$str1, $str2</arglist>
<notes>Compares 2 strings and count how many shared charactes they have.
Non case-sensitive comparision!</notes>
</func>
<alias name="pat_srcComp" language="Lua" id="9">
<value>if not strSharedChars then
function strSharedChars(str1, str2)
--------------------------------------
-- Compares 2 strings and count how --
-- many shared charactes they have --
--------------------------------------
local i, len
local c1, c2 -- characters to compare
local count = 0
--Suppressing Lua's attempts to get length of a number
--if str1 or str2 are numbers (will cause an error)
str1 = tostring(str1)
str2 = tostring(str2)
len = math.min(str1:len(), str2:len())
for i = 1, len do
--Get next char and bring it to lowercase
--Will use non case-sensitive comparision
c1 = str1:sub(i, i):lower()
c2 = str2:sub(i, i):lower()
if(c1 ~= c2) then
break
end
count = count + 1
end
return count
end
end</value>
</alias>
|
|
|
|
|
 |
wrym Magician
Joined: 06 Jul 2007 Posts: 349 Location: The big palace, My own lil world
|
Posted: Mon Apr 27, 2009 6:01 pm |
Fang, your right, I hit this problem, posted and started to work on a work around, and then said this is stupid, and put it all into lua. <3 for onload events and global lua environments. I had been trying to set up a recursive function and boiled my problem down to this test code.
Arde, your code works for me, but, you've an Arglist, and using zs.param, might be getting a conflict of some sort there |
|
_________________ "To the engineer, all matter in the universe can be placed into one of two categories: (1) things that need to be fixed, and (2) things that will need to be fixed after you've had a few minutes to play with them" - Scott Adams, The Dilbert Principle |
|
|
 |
Arde Enchanter
Joined: 09 Sep 2007 Posts: 605
|
Posted: Mon Apr 27, 2009 6:40 pm |
wrym
Yeah... I have CMUD restarted and everything work again... Please, ignore my previous post.
Arglist is ok since it is a zScript function. |
|
_________________ 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 |
|
|
 |
|
|
|