Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different interpretation of lists in func args #92

Closed
xanathar opened this issue Jun 5, 2015 · 2 comments
Closed

Different interpretation of lists in func args #92

xanathar opened this issue Jun 5, 2015 · 2 comments
Assignees
Milestone

Comments

@xanathar
Copy link
Member

xanathar commented Jun 5, 2015

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!

@xanathar xanathar added this to the 0.9.8 milestone Jun 5, 2015
@xanathar xanathar self-assigned this Jun 5, 2015
@xanathar
Copy link
Member Author

xanathar commented Jun 5, 2015

In progress, there are actually more than one bugs.
(note to self: the first one at least is in the implementation of the ARGS instruction)

xanathar added a commit that referenced this issue Jun 15, 2015
@xanathar
Copy link
Member Author

Done in 0.9.6.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant