lua-users home
lua-l archive

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


On Tue, Oct 23, 2012 at 1:56 PM, spir <denis.spir@gmail.com> wrote:
PS: Once the file (module) where this is defined is loaded, which io.open is accessible to other files (in case the new def belongs to what you export from the defining module)? Both cases would probably be useful... 

I am not sure what you mean here. When you run the do...end block I gave you from that point on all code that tries to access the global io.open function will access the wrapper function. Of course if someone BEFORE the do...end block did myioopen=io.open he can still access the original io.open function as myioopen(file,mode). AFAIK there is no difference if you physically place that block in a separate file and include it with dofile or with require or if you just copy paste it to the top of your main file before any require statements. As long as this block runs before anyone is able to run or grab the old io.open, it should work.

PS: security wise you have to follow Elias' advice. If you run untrusted code be careful what libraries you expose to it. If you are using Lua 5.2 you can use load() to sandbox function by providing a safe environment for them to run in.