lua-users home
lua-l archive

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


On Tue, Dec 28, 2010 at 06:33, Alexander Gladysh <agladysh@gmail.com> wrote:
> On Tue, Dec 28, 2010 at 06:16, Patrick Mc(avery
> <spell_gooder_now@spellingbeewinnars.org> wrote:

> Any known symbols used in handler are imported in the generated code
> as needed, if anything that is not known is met, generation fails.

I think that a synthetic example is in order:

api:call "foo"
{
  handler = function(context)
    assert(write_file("/tmp/out.txt", "42"))
  end;
}

Translates to

local assert = assert
local write_file = import 'lua-aplicado/filesystem.lua' { 'write_file' }

local handler = function(context)
  assert(write_file("/tmp/out.txt", "42"))
end

return
{
  handler = handler;
}

That import() is a simple wrapper around loadfile() or require():

https://github.com/lua-nucleo/lua-nucleo/blob/master/lua-nucleo/import.lua
https://github.com/lua-nucleo/lua-nucleo/blob/master/lua-nucleo/import_as_require.lua

Alexander.