0
votes

I have some problems with C# luainterface library:

1. So I load a script and extract its functions like that:

LuaFunction function = lua.GetFunction("Update"); 

But what if I load two different scripts that contains functions with the same name. How to extract two different functions with the same name from script1 and script2?

2. If I load functions into memory, is it possible to dispose a specific one, not all functions?

3. When I use Lua.DoFile method I want to execute specific function from the file. Any ideas how to do that?

Edit

2. I found, that I can do something like this

string f = @"
        function hh()
          end";

        var result = lua.DoString(f)[0] as LuaFunction;

but for some reason I get null exception. Any ideas why?

1

1 Answers

0
votes

DoString will return what your script return.

lua.DoString ("return 10+10")[0]; // <-- will return Double. 20

If you want to get your Lua function as LuaFunction object you need to return your function, or even better just use the [] operator to get the global value of hh.

lua.DoString ("function hh() end");
var hh = lua["hh"] as LuaFunction;
hh.Call ();

Here is a example: https://github.com/codefoco/NLuaBox/blob/master/NLuaBox/AppDelegate.cs#L46 (but Using NLua instead LuaInterface)

And remember to release your LuaFunction calling Dispose when you don't need the function anymore.