I'm using the LuaInterface in .net for a large project I'm working on. Is it possible to convert a string straight into a LuaFunction (similar to how LoadString() works?).
Asked
Active
Viewed 352 times
-1
-
2Doesn't LuaInterface have `LoadString` or some equivalent? If not, it's not a good interface to Lua, and it should probably change its name ;) – Nicol Bolas Sep 28 '11 at 18:41
-
@Nicol You can run a string, yes. I need to convert a string to a `LuaFunction` object. – Freesnöw Sep 28 '11 at 21:20
-
`lua_loadstring` does not run the string. It loads it, converting it into a function which it pushes onto the stack. If LuaInterface has a special object for Lua functions, then LuaInterface's equivalent of `lua_loadstring` should return that special object. Or something else that is callable. What does it return? – Nicol Bolas Sep 28 '11 at 23:47
-
It returns what the script it runs returns (e.g. `return 3` is my Lua script would return 3). – Freesnöw Sep 29 '11 at 08:07
1 Answers
2
LuaInterface has LoadString
, that is how you get lua source code parsed into a LuaFunction
, you can then use the Call
method to execute the function.
static void Main(string[] args) {
Lua lua = new LuaInterface.Lua();
LuaFunction func = lua.LoadString("return 5", "name for debugging");
func.Call();
}

sylvanaar
- 8,096
- 37
- 59