lua-users home
lua-l archive

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


Am 19.04.11 11:11, schrieb Marc Balmer:
> Our webapplications at the moment use Lua to prepare data to be sent to
> the browser and ClearSilver to render webpages, i.e. to mix the data and
> the template.
> 
> Now we wrote a new templating system (we call it Lua Templates) which
> could one day replace ClearSilver in our products.  For security reasons
> we do not want to run the template renderer in the same Lua state we do
> the data preparation in.  Is there a way to access objects from one
> state in another state?  Something like proxy tables, that behave like
> normal tables, but actually are store in different state?
> 
> The idea is to have the template engine to run in a sandbox of its own,
> preventing access to data and methods the data processing state uses
> (like e.g. DB connections etc.)
> 
> Any ideas?

Thanks for the public and private feedback I got on this issue.  I was
able to achieve my goal and I have now proxy capability like I wanted
them.  I am always impressed again what can be achieved with Lua...

p = proxy.new() -- sample function to create new state

-- create table query { op = 'test', data = 42 } in the new state
p.query = {
	op = 'test',
	data = 42
}

p:dostring('print(query.data)')	-- prints 42

p.query.op = 'another op'

And just for fun, even this works:

p:dostring([[function test()
  print('test function from the other state')
end]])

p.test()

I our real world application we do not use proxy.new() or dostring(),
the other state is being created by the C app and there is a function to
get it.