简体   繁体   中英

luainterface problems

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM