lua-users home
lua-l archive

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


> -----Original Message-----
> From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On
> Behalf Of steve donovan
> Sent: woensdag 30 april 2014 10:04
> To: Lua mailing list
> Subject: Re: How to load more than a file from C
> 
> On Wed, Apr 30, 2014 at 9:55 AM, Igor Trevisan <igt1972@gmail.com> wrote:
> > The problem is that I don't want to collect the lua files but
> > keep them detached.
> 
> Ah yes, you keep them on the USB stick... as I understand, you want a
> function available that comes from another file.  Could you not just
> use require() to load the other file from the main script?
> 
> Alternatively, if all these functions are global in your state, then
> after loading the files all the functions will be available when you
> start running the main function.

Depending on the type of system, it requires that a filesystem is present and you need to point the LUA_PATH environment variables to your USB location.

According to your example, below the module (in file_y) and program (in file_x)

file_y.lua
==========
local M = {}  -- define module table

M.func_y = function()    -- define function inside module table
   print("func_y was called")
end

return M    -- return module table

file_x.lua
==========
local file_y = require("file_y")   -- load your module

local func_x = function()
   file_y.func_y()   -- call the function in the other module
   print("func_x was called")
end

-- here is where your program starts
func_x()  -- call func_x




hth
Thijs