2

I have a function

function f1(msg) return value end

in Lua file A.lua, how i can call this function or the return result of this function from a B.lua Thank you Jp

2 Answers 2

6

You use the require function ( http://www.lua.org/pil/8.1.html )

require("A")
f1("my message")
Sign up to request clarification or add additional context in comments.

Comments

1

As a complement to brianm, you can also

dofile("A.lua")
f1("blah")

or

local chunk = assert(loadfile("A.lua"))
chunk()
f1("blah")

1 Comment

Since require must be without the .lua extension, it isn't possible to load lua files with other extension than .lua. The dofile solution works for any lua file extension.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.