0

I am writing a scripting engine for my game using the LuaInterface library. I am getting an error when attempting to instantiate the class in Lua. The error is:

"./Scripts/sv_worldgen.lua:2: attempt to call global 'Campfire' (a string value)"

Where sv_worldgen.lua is (in entirety):

function GenerateChunk(worldChunk, chunkGridPosition)
    tf = Campfire()
    tf:SetPosition(chunkGridPosition)
end

Campfire is a class in C#, and appears to be exposed to lua as per the CLRPackage example and of course the LuaInterface Reference. I cannot seem to get around this error, and I have done due diligence of searching. The only other behavior of the script I can manage throws a similar error, but where it is "(a table value)". What am I doing wrong? Thank you in advance!

I tried explicitly doing Campfire._ctor(), but _ctor() is a string value.

selkathguy
  • 1,171
  • 7
  • 17
  • How are you exposing your class to lua? How are you loading it in lua? – Etan Reisner Apr 03 '14 at 17:28
  • `LoadScript("sh_CLRPackage.lua")` and then `import "JASG"`. I have updated the question. This is now telling me that `Campfire` is a string value. – selkathguy Apr 03 '14 at 18:00
  • you're going to have to show how Campfire is exposed to Lua. Without that, it is impossible to say. – Oliver Apr 06 '14 at 02:11
  • @Schollii `lua["Campfire"] = typeof(Campfire);` gives me that Campfire is a userdata value. If I leave that out and let luainterface do its job of accessing my assembly classes, the error is on the next line with `"attempt to call method 'SetPosition' (a string value)"` – selkathguy Apr 07 '14 at 18:26
  • Maybe the problem is at the C# level. Show the minimal .cs that produces the problem. – Oliver Apr 08 '14 at 14:19

1 Answers1

0

This was resolved by using CLRPackage and using it to first load the assembly.

//Lua
JASG = CLRPackage("JASG", "JASG")

Then and only then can you link the classname to the actual C# class using (this must be done before trying to access it in Lua):

//Lua
Campfire=JASG.Campfire;

and then normal instantiation can occur by

//Lua
cf = Campfire()
selkathguy
  • 1,171
  • 7
  • 17