lua-users home
lua-l archive

Re: Protecting global variables

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


Peter, assuming I understood correctly what you want to do, you could also consider a sandbox approach, rather than filtering _G access: - Create a table that will be your user's global table. You could start with an empty table, or include some globals:
 userGlobal = { print=print, string=string, myvar=myvar }
- Attach a metatable to handle your special variables (as you already did).
- Execute user's code with that table as environment (using sefenv() in Lua 5.1 or setting _ENV in Lua 5.2).
--
 Enrico

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