Calling Basic Functions

Jun 18, 2014 at 1:50 AM

First off I want to go ahead and thank you for your library. So far it looks awesome and I appreciate the time you continue to put into this project.

I am coming from using LuaInterface and NLua, I finally got tired of the memory errors so I am hoping to convert my code over to use your library without too much trouble.

My one and only problem is not being able to call functions like I was able to in the past. Right now I have several .lua files that contain various functions to be called later from the application.

I load up the lua files using
Engine.DoFile("xyz.lua") (please excuse the use of VB)
Engine is the created environment.

Then later on I am trying to call functions that I believe are loaded into memory using the function name (string) and an object() array like LuaInterface/NLua accepted.

Right now I am trying to use Engine.DoChunk("function name","test.lua",not completely sure)

I have a general function that does some logging before calling each lua function which is why I am using the object() array. Is there any good way to convert the array to the keypairs for the function to work? Am I even going about this the correct way?

Thanks for all replies/solutions!
Jun 18, 2014 at 10:37 PM
Thank, and by the way you descriped why I startet this project. NLua in 24/7 environment is not possible. Way to many memory leaks.

After you executed the script via DoChunk you can access every global variable of the environment. And a function is also a variable of the type delegate. So, you just call the delegate.
Delegate dlg =Engine["function_name"] as Delegate;
if (dlg != null)
  dlg.DynamicInvoke(new object[]{ ... }); // there is the object array
You do not need any KeyValuePairs on a compiled function, because the arguments are well known. If you need, you can retrieve the arguments with .net reflection.
I like Lua for this scenario, because Lua does not know byref/out/ref variables. So, it feels natural for dynamic calls.

Compiling a new chunk is not necessary.
Marked as answer by jcsnider on 6/18/2014 at 4:48 PM
Jun 18, 2014 at 11:48 PM
Haha, that is exactly what I needed! Thanks!!!