I’m trying to embed some Lua scripting functionality in my C# app by using LuaInterface 2.0.3. This is working just fine so far, but I can’t figure out how to restrict access to only few specified .Net classes. By default, all .Net libraries are directly accessible through “luanet” and Lua scripts are free to open new windows or access the file system.
e.g. this Lua script will open a new Window:
Form = luanet.System.Windows.Forms.Form
mainForm = Form()
mainForm:ShowDialog()
Freedom of scripting is great and all, but this is likely to interfere with the hosting app and has some security-related implications I’m not too fond of. Is there any way to disable this?
You could also do this in reverse, removing the global and stored instances of LuaInterface first and then doing all the work through a local reference (which all code in the rest of the block can use):
(You can avoid the three-step name-preservation dance above (
local luainterface=luanet; luanet=nil; local luanet=luainterface) by localizing directly toluanetand then deleting the global through the_Greference to the global table:I just chose not to as a matter of personal preference.)