lua-users home
lua-l archive

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

Nick Tourte wrote:

You can call dofile in a script to load and execute the
main body of another script, and you can call loadfile to
load the main body into a function and run it upon a
function call; but I can't seem to find a way to call a
function that is registered in another such script.

A function definition is basically an assignment statement,
which needs to be executed before the function is created
and given a name.  Use dofile (or loadfile and a function
call) to execute the script, and then simply call the
function like you would if it were in the same file.

If you don't know the function's name until runtime, do
something like the following:

Lua 5.1.1  Copyright (C) 1994-2006, PUC-Rio
FncName = "print"
-- Or this: