How Can I Get Param In lua script when I Call CallByParam #384
Unanswered
2276282419
asked this question in
Q&A
Replies: 2 comments
-
L.SetGlobal("hello", fn) |
Beta Was this translation helpful? Give feedback.
0 replies
-
The function LoadString returns the full string. So each time you call fn it redefines hello. In this case err := L.DoString(`
function hello(message_part)
print(message_part)
return "hi"
end
hello("e")
`)
if err != nil {
panic(err)
}
err = L.CallByParam(lua.P{
Fn: L.GetGlobal("hello"),
NRet: 1,
Protect: true,
}, lua.LNumber(10))
if err != nil {
panic(err)
} Alternatively you could call fn to actually define hello. fn, err := L.LoadString(`
function hello(message_part)
print(message_part)
return "hi"
end
hello("e")
`)
if err != nil {
panic(err)
}
err = L.CallByParam(lua.P{
Fn: fn,
NRet: 0,
Protect: true,
})
if err != nil {
panic(err)
}
err = L.CallByParam(lua.P{
Fn: L.GetGlobal("hello"),
NRet: 1,
Protect: true,
}, lua.LNumber(10))
if err != nil {
panic(err)
} Output is in both cases:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Please answer the following before submitting your issue:
Beta Was this translation helpful? Give feedback.
All reactions