lua-users home
lua-l archive

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


> 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