Skip to content

Maintaining Visibility

TheModMaker edited this page Aug 13, 2012 · 2 revisions

When a type is registered to Lua, all members (both static and instance) that are marked with public are visible. To access static members within Lua, get/set the member of the type (e.g. int.MaxValue). If a delegate, whether explicitly registered using Lua.Register(Delegate) or accessed through a registered type, returns a type that is not explicitly registered, it is still accessible to Lua by default; however, Lua will not be able to access static members or create a new instance. There are two ways to restrict the visibility of members and types:

First, use LuaIgnoreAttribute. When applied to a member, that member will not be accessible within Lua. When applied to a type, none of it's members will be accessible, but the value can exist within Lua so it can be passed back to .NET. LuaIgnoreAttribute is not inherited, so a derived type will be visible by default.

Second, return ReturnInfo. When a delegate returns ReturnInfo, it is converted into a LuaUserData object that exists in Lua. This makes only certain members accessible within Lua. If a LuaUserData is passed back to .NET, the underlying value is passed. ReturnInfo defines which members can be accessed, any other member will not be. The constructor ReturnInfo(bool) defines whether all members can be access, true will be the same as passing the value normally, false will make none of the members visible. The constructor ReturnInfo(params string[]) accepts a params array of member names that can be accessed. This applies to methods, properties, fields, and operators (see .NET's definition of operator names).

Next: Environment

Clone this wiki locally