lua-users home
lua-l archive

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


On 23.02.2011 22:30, Jeff Smith wrote:

> Any advice or code examples would be welcomed please. Thanks

How about this:
$ mkdir -p com/example/
$ cat > com/example/graphics.lua
local M={}

function M:test()
  return 'Tested'
end

return M

$ lua -e 'graphics=require "com.example.graphics"; print(graphics:test())'

So you make a local module and put it inside a namespace by installing
it in your subdirectory (com/example), and return just a table. Then the
caller decides where to assign the required module.
Calling graphics:test() is faster than calling com.example.graphics:test().
You can also move your module to another subdirectory, and would need to
change only 1 line of the caller code - no changes to the module itself.
This is lua 5.2 compatible. The above module is in plain lua, but you
could do the same for C bindings.

Regards,
miko