I'm integrating LuaInterface into a c# program using LuaInterface. I want to be able to write scripts that can access C# methods in the program.
The methods that it is accessing are in separate "subsystems" and I wanted to have the Lua method define the subsystem, then the method using . as a separator. e.g. SubsystemName.MethodName
but this throws an exception when I try to register the method. I've changed it to _ and it works perfectly. Is there anyway to get it working with .? The program has other interfaces for calling these methods like JSON-RPC via HTTP and these use the . notation so would like it to be consistent.
You can define your methods using _
as a separator in your .NET code, e.g. SubsystemName_MethodName
. Then create a simple Lua module, that does roughly the following:
local YourClass = luanet.import_type("Your.Binding.Class")
SubsystemName = {} -- create a global table
SubsystemName.MethodName = YourClass.SubsystemName_MethodName
This will allow you to use SubsystemName.MethodName
in Lua.
Instead of doing it manually (which can be tedious and error-prone), you can use a code generator that creates the Lua code from a list of classes/methods.