I tried to provide some script features in my C# App.
After some searches, The Lua and LuaInterface looks like a reasonable way to do it.
By embedding a Lua VM in my C# code, I can load a Lua script and process methods
defined in the C# class without any problems.
However, I wonder is there a way to not only execute a lua script file in
my c# program, but also to have a lua interactive prompt in my program?
Thus I can type commands and see the returns immediately.
Any hint about where I should start to work on it will be very helpful!
Best Regards
Lua’s
debugmodule contains a very basic interactive console:debug.debug()(the Lua manual suggests this module should be used only for debugging).If that doesn’t meet your needs, it’s easy enough to implement one yourself. If you were to write it in Lua itself, the absolute bare bones console would be:
That’ll crash on either a syntax or runtime error. A slightly less minimal version, which captures (and ignores) errors:
This could be enhanced by displaying syntax errors (second return value from
loadstringon failure), runtime errors (second return value frompcallon failure), return values from evaluated code ([2..N] return values frompcallon success), etc.If you want to get really fancy, you can allow people to enter multi-line statements. Look at
src/lua.cin the source distro to see how this is done.