Only call the function and not run the whole script #446
Answered
by
cloudwindy
techierishi
asked this question in
Q&A
-
I want the know if there is a way to only call the function present in the Lua script. I don't want rest of the script to run. for example: test.lua function test()
return "test string"
end
print("Hello World!") Now in following go code whole above lua script is running including the print statement. I just want L := lua.NewState()
L.DoFile(filePath)
defer L.Close()
luaFn := L.GetGlobal("test")
if luaFn == lua.LNil {
return nil, fmt.Errorf("function not found")
}
err := L.CallByParam(lua.P{
Fn: luaFn,
NRet: 1,
Protect: true,
}) |
Beta Was this translation helpful? Give feedback.
Answered by
cloudwindy
Jul 17, 2023
Replies: 1 comment
-
I don't think it's possible, the whole script have to be executed to get the function. Imagine this situation:
Any part of the code can effectively change how the behavior of that function. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
techierishi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't think it's possible, the whole script have to be executed to get the function. Imagine this situation:
Any part of the code can effectively change how the behavior of that function.