You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to run down a problem in my scripts which seems to point to a difference in how the Lua 5.2 from lua.org thinks lists get passed into params, and how Moonsharp 0.9.6 does it.
I adapted these into functions which report on their arguments, and added a couple of functions h() and i() illustrating how passing through varargs works:
function f(a,b)
local debug = "a: " .. tostring(a) .. " b: " .. tostring(b)
return debug
end
function g(a, b, ...)
local debug = "a: " .. tostring(a) .. " b: " .. tostring(b)
local arg = {...}
debug = debug .. " arg: {"
for k, v in pairs(arg) do
debug = debug .. tostring(v) .. ", "
end
debug = debug .. "}"
return debug
end
i(3) a: extra b: 3 arg: {}
i(3,4) a: extra b: 3 arg: {4, }
i(3,4,5,8) a: extra b: 3 arg: {4, 5, }
i(5,r()) a: extra b: 5 arg: {1, 2, 3, }
When run inside MoonSharp in Unity 5.02, I get the following results (I accumulated the returns and sent them in a debug statement, otherwise the same)
-- all of the following are off:
h(3) a: 3 b: nil arg: {}
h(3,4) a: 3 b: nil arg: {}
h(3,4,5,8) a: 3 b: nil arg: {}
h(5,r()) a: 5 b: nil arg: {}
-- all of the following are off:
i(3) a: extra b: 3 arg: {}
i(3,4) a: extra b: 3 arg: {}
i(3,4,5,8) a: extra b: 3 arg: {}
i(5,r()) a: extra b: 5 arg: {}
So it seems as though lists (the return from r() and the value of "...") are being interpreted as scalars, and only the first element is being used.
Am I missing something?
Failing that, is this intended behaviour in MoonSharp?
Finally: any workarounds? I don't really want to change my functions to operate in table context eg: f{a=1, b=2} etc.
Thanks for your insight!
The text was updated successfully, but these errors were encountered:
Description taken from : https://groups.google.com/forum/#!topic/moonsharp/fCJDH8pYIv0
Hi,
I was trying to run down a problem in my scripts which seems to point to a difference in how the Lua 5.2 from lua.org thinks lists get passed into params, and how Moonsharp 0.9.6 does it.
From the lua.org manual http://www.lua.org/manual/5.2/manual.html#3.4.10 they do an example with functions f(), g(), and r().
I adapted these into functions which report on their arguments, and added a couple of functions h() and i() illustrating how passing through varargs works:
function f(a,b)
local debug = "a: " .. tostring(a) .. " b: " .. tostring(b)
return debug
end
function g(a, b, ...)
local debug = "a: " .. tostring(a) .. " b: " .. tostring(b)
local arg = {...}
debug = debug .. " arg: {"
for k, v in pairs(arg) do
debug = debug .. tostring(v) .. ", "
end
debug = debug .. "}"
return debug
end
function r()
return 1, 2, 3
end
print ("f(3) ", f(3))
print ("f(3,4) ", f(3,4))
print ("f(3,4,5) ", f(3,4,5))
print ("f(r(),10) ", f(r(),10))
print ("f(r()) ", f(r()))
print()
print ("g(3) ", g(3))
print ("g(3,4) ", g(3,4))
print ("g(3,4,5,8)", g(3,4,5))
print ("g(5,r()) ", g(5,r()))
print()
-- pass thru varargs to g()
function h(...)
return g(...)
end
print ("h(3) ", h(3))
print ("h(3,4) ", h(3,4))
print ("h(3,4,5,8)", h(3,4,5))
print ("h(5,r()) ", h(5,r()))
print()
-- pass thru varargs to g(), adding one
function i(...)
return g('extra', ...)
end
print ("i(3) ", i(3))
print ("i(3,4) ", i(3,4))
print ("i(3,4,5,8)", i(3,4,5))
print ("i(5,r()) ", i(5,r()))
print()
The results, running in lua on my desktop are what I'd expect:
f(3) a: 3 b: nil
f(3,4) a: 3 b: 4
f(3,4,5) a: 3 b: 4
f(r(),10) a: 1 b: 10
f(r()) a: 1 b: 2
g(3) a: 3 b: nil arg: {}
g(3,4) a: 3 b: 4 arg: {}
g(3,4,5,8) a: 3 b: 4 arg: {5, }
g(5,r()) a: 5 b: 1 arg: {2, 3, }
h(3) a: 3 b: nil arg: {}
h(3,4) a: 3 b: 4 arg: {}
h(3,4,5,8) a: 3 b: 4 arg: {5, }
h(5,r()) a: 5 b: 1 arg: {2, 3, }
i(3) a: extra b: 3 arg: {}
i(3,4) a: extra b: 3 arg: {4, }
i(3,4,5,8) a: extra b: 3 arg: {4, 5, }
i(5,r()) a: extra b: 5 arg: {1, 2, 3, }
When run inside MoonSharp in Unity 5.02, I get the following results (I accumulated the returns and sent them in a debug statement, otherwise the same)
f(3) a: 3 b: nil
f(3,4) a: 3 b: 4
f(3,4,5) a: 3 b: 4
f(r(),10) a: 1 b: 10
f(r()) a: 1 b: nil -- expected b: 2
g(3) a: 3 b: nil arg: {}
g(3,4) a: 3 b: 4 arg: {}
g(3,4,5,8) a: 3 b: 4 arg: {5, 8, }
g(5,r()) a: 5 b: 1 arg: {} -- expected arg: {2, 3}
-- all of the following are off:
h(3) a: 3 b: nil arg: {}
h(3,4) a: 3 b: nil arg: {}
h(3,4,5,8) a: 3 b: nil arg: {}
h(5,r()) a: 5 b: nil arg: {}
-- all of the following are off:
i(3) a: extra b: 3 arg: {}
i(3,4) a: extra b: 3 arg: {}
i(3,4,5,8) a: extra b: 3 arg: {}
i(5,r()) a: extra b: 5 arg: {}
So it seems as though lists (the return from r() and the value of "...") are being interpreted as scalars, and only the first element is being used.
Am I missing something?
Failing that, is this intended behaviour in MoonSharp?
Finally: any workarounds? I don't really want to change my functions to operate in table context eg: f{a=1, b=2} etc.
Thanks for your insight!
The text was updated successfully, but these errors were encountered: