lua-users home
lua-l archive

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


Thanks
I have solved my problem!

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

Hi Daniel,
My trouble is:
In File 2:
Function some_other_functions(xxx)
End

function main()
	--do something
	--call to other function in file 2
end
----------------------end of file 2------------
and in file 1, I do not know how to call the function main in file 2, and
file 2 will be create at run time or even load from database in to memory!
Please help me
Thanks Daniel,

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Daniel Collins
Sent: Wednesday, July 19, 2006 12:15 PM
To: Lua list
Subject: Re: call a function in other script from a script

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
 

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com