.net - Embedded a Lua interactive prompt window in C# -
i tried provide script features in c# app. after searches, lua , luainterface looks reasonable way it. embedding lua vm in c# code, can load lua script , process methods defined in c# class without problems.
however, wonder there way not execute lua script file in c# program, have lua interactive prompt in program? can type commands , see returns immediately.
any hint should start work on helpful!
best regards
lua's debug
module contains basic interactive console: debug.debug()
(the lua manual suggests this module should used debugging).
if doesn't meet needs, it's easy enough implement 1 yourself. if write in lua itself, absolute bare bones console be:
while true io.write("> ") loadstring(io.read())() end
that'll crash on either syntax or runtime error. less minimal version, captures (and ignores) errors:
while true io.write("> ") local line = io.read() if not line break end -- quit on eof? local chunk = loadstring(line) if chunk pcall(chunk) end end
this enhanced displaying syntax errors (second return value loadstring
on failure), runtime errors (second return value pcall
on failure), return values evaluated code ([2..n] return values pcall
on success), etc.
if want really fancy, can allow people enter multi-line statements. @ src/lua.c
in source distro see how done.
Comments
Post a Comment