lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I generally use "require" to ensure visibility between different script
files. 

file1:
function main()
	print("main\n")
end

file2.lua:
require "file1"
main() -- calls main defined in file1

You can also use "dofile" or "loadfile". It is worth reading the
reference manual and the Programming in Lua book to learn the
differences between all these approaches. The thing I like about require
is the way it ensures that each file is only loaded once. That way I can
use require at the top of every script in a similar way to using
#include in C/C++, just to make sure things are visible but without the
overhead of loading the files more than once.

- DC


-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Nguyen Dang
Quang
Sent: Wednesday, 19 July 2006 2:33 PM
To: lua@bazar2.conectiva.com.br
Subject: call a function in other script from a script


Hi,
In my LUA script, I have to call  a function "main" in other scripts but
I do not know how to do that. Please help me.
For example:
In 2nd script:
 
function add(x,y)
            return x+y
end
 
function main()
            print(add(5,3))
end
 
Thanks