[Sputnik-list]luaenv.Sandbox (was : proposed versium
modifications)
Yuri Takhteyev
yuri at sims.berkeley.edu
Fri Mar 7 06:08:04 GMT+2 2008
> In the same way, you can split do_lua in 2 version :
>
> -- will report error in err
> values, err = luaenv.Sandbox:new{x = 1, y = 2}:do_lua_safe("z = x + y")
>
> -- will halt with proper error report
> values = luaenv.Sandbox:new{x = 1, y = 2}:do_lua_fail("z = x + y")
Maybe, but as long as do_lua == do_lua_fail, you can trivially
simularte do_lua_safe with a pcall:
values, err = pcall(env.do_lua, env, "z = x + y")
Considering this, I would put this off until we see that this is use
so frequently that all the pcalls start getting on our nerves.
Of course, if some other project wants to use luaenv but needs the
do_lua_safe(), they can submit a patch...
> If each case get is own function it would make code self documented.
"pcall" is more self-documenting that do_lua_safe / do_lua_fail, if you ask me.
> An other thing that can be clean by using an external module/Rocks :
> Logging.
> It is passed down to luaenv and it isn't clear how other module handle
> it :
> - get one at instantiation ?
> - query one in sputnik global space ?
That's a tricky issue that already came up with Versium. Looking for
Sputnik-specific globals is not an option, since the library might be
called by some other client. I suggest the following:
local logger = self.logger or logger -- module level variable that the
user would set with luaenv.logger = mylogger
if logger then logger:log(...) end
This way the client has two options: set a logger on the module:
require"luaenv"
luaenv.logger = logging.file(...)
or set it on individual sandboxes:
sandbox = luaenv.Sandbox:new(...)
sandbox.logger = ...
or not set it at all, in which case no logging occurs.
> Actual scheme isn't very constant and it's a bit cumbersome to pass a
> logger reference all the way down.
Agreed.
--
http://sputnik.freewisdom.org/
More information about the Sputnik-list
mailing list