Reputation: 71
We are doing a project in .NET framework and want to make most of its functionalities available later for Lua scripts. I thought I could compile a dll and load it to Lua script with the help of LuaInterface. But somehow it did not work.
What DID work is the following:
require 'luanet'
luanet.load_assembly("System.Windows.Forms")
Form = luanet.import_type("System.Windows.Forms.Form")
Button = luanet.import_type("System.Windows.Forms.Button")
form1 = Form()
button1 = Button()
As you can see, here I'm loading standard assembly and types, which didn't cause much problem. However, if I have my own dll 'LuaTest' compiled under .NET 4.0 and try to load it in LUA. It did not work. I wrote something like,
require 'luanet'
luanet.load_assembly("LuaTest")
PlanetarySystem = luanet.import_type("LuaTest.PlanetarySystem")
solarSystem = PlanetarySystem()
where 'PlanetarySystem' is a class in LuaTest. If I run this piece of code, the interpreter would say: attempt to call global 'PlanetarySystem' (a nil value).
I also tried another way to load the dll:
package.path = package.path .. ";" .. "/?.dll"
require 'luanet'
require 'LuaTest'
After run, the interpreter throws: lua: error loading module 'LuaTest' from file '.\LuaTest.dll': The specified procedure could not be found.
I'm quite a newbie to .NET framework and LuaInterface. Perhaps I did something utterly wrong. Please help me on this. Many thanks!
Edit: Perhaps I should have an 'Entry Point' for Lua in my dll to indicate that this dll is LUA loadable???
Edit: Lua not LUA. No offense to Portuguese speaking people. The Lunanet I'm using must be compatible with .NET 4.0, otherwise the first piece of code would not work.
Upvotes: 5
Views: 2366
Reputation: 61
Try this link. I posted a solution which works fine! If your pc is well prepared (installed lua & C#2010 e.g.) then copy the C# code to a dll project and build it. Then make sure that your dll is located in a registered directory for your lua environment and execute the lua script which is shown in the same post.
An additional note for you: I needed to use .NET 3.5 framework. With .NET 4.0 LuaInterface did not work for me.
Upvotes: 0
Reputation: 71
I believe you are confusing the assembly name with being a required part of the fully qualified name of the type that you are trying to import. The error indicates that the PlanetarySystem class is a "a nil value", meaning that it likely couldn't find a class by that fully qualified name. I would be certain on the namespace that your class was in.
Second, if my first recommendation doesn't work, you may need to make your classes ComVisible so that the Lua engine can see your classes.
http://msdn.microsoft.com/en-us/library/ms182157.aspx
Upvotes: 1