1

Im using the LuaInterface for C#.

In my C# project i got the file Program.cs

which uses the namespace Test and the class is called Program.

In the class Program, i got the method PrintTest().

How do i reach that method from Lua? I have tried something like this:

luanet.Test.Program:PrintTest();

But lua says "No such method".

I have been looking at this thread: LuaInterface - how-to restrict access to .Net classes? and managed to create a form like he does, so the problem only occurs with my own custom classes.


Okey. The problem seems to be that the method PrintTest is static. If i make it non-static it works, but how do I do if I want it to be static?

Community
  • 1
  • 1
joxxe
  • 261
  • 1
  • 3
  • 13

2 Answers2

1

Despite the age of this thread, I had the same question and was able to find a satisfactory answer.

As of LuaInterface 1.5.1, to call a static method on a type, you simply use the dot operator.

ex:

luanet.load_assembly("AssemblyName")
local Test = luanet.import_type("Test.Program")
Test.PrintTest()

Reference: https://github.com/megax/LuaInterface

Larkspur
  • 11
  • 2
0

It usually looks something like this:

luanet.load_assembly("YourAssembly")
local Test  = luanet.import_type("Test.Program")
local test = Test()
test.PrintTest()
Mud
  • 28,277
  • 11
  • 59
  • 92
  • Forgot to say that the method PrintTest is static. Im trying the code you posted but getting an error on row 2. It says No such type. – joxxe Jun 18 '12 at 08:08
  • Did you adjust line 1 to include the name of your assembly? Are you loading this via the LuInterface runner, or are you hosting LuaInterface in your application? – Mud Jun 18 '12 at 20:45