lua-users home
lua-l archive

Re: Is Lua used as a data representation language?

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


Am 08.01.2013 um 18:10 schrieb Roberto Ierusalimschy <roberto@inf.puc-rio.br>:
>> On Tue, Jan 8, 2013 at 5:31 PM, Ashwin Hirschi <lua-l@reflexis.com> wrote:
>>> It doesn't seem to handle a simple case like:>
>>> while 1 do end
>> 
>> OK, thanks - I'll try to close some more gaps. The approach here is
>> static checking, unlike the runtime limits Roberto suggests.
> 
> Another runtime aproach is this:
> 
> function loaddata (data)
> local f = assert(loadstring("return (" .. data .. ")"))
> local count = 0
> debug.sethook(function ()
> count = count + 1
> if count >= 2 then error"cannot call functions" end
> end, "c")
> local res = f()
> count = 0
> debug.sethook()
> return res
> end
> 
> It only allows expressions (no variables, no assignments) and disallows
> any kind of function calls.
> 
> -- Roberto
> 
that's kinda sweet...

AltStyle によって変換されたページ (->オリジナル) /