c# - Return a String with LuaInterface -


so, i'm trying implement lua scripting language in c#. it's simple enough, really, if use part of console application. want able create game console within xna. problem lua.dostring() seems return console line, rather string - which, said, fine console applications, want add output buffer string can display in-game, rather in console window. apologize if confusing - code clear up.

using system; using system.collections.generic; using luainterface;  namespace luaconsolelibrary {     public class luaconsole     {         private lua lua;          private bool isrunning = true;         private string input;         private list<string> outputbuffer;          public bool isrunning         {             { return isrunning; }         }          public luaconsole()         {             this.lua = lua;         }          public void run()         {             int = 0;             while(isrunning)             {                 outputbuffer.add("> ");                  input = console.readline();                 outputbuffer.add("");                  try                 {                     lua.dostring(input);                 }                 catch(exception e)                 {                     outputbuffer.add(e.message);                 }                                 {                     outputbuffer.add("");                 }             }         }     } } 

basically, i'm confused why lua.dostring(input); should work opposed having use console.writeline(lua.dostring(input));. i've tried outputbuffer.add(lua.dostring(input).tostring());, which, being tostring valid there, should work in theory. instead performs lua.dostring , throws exception - "object reference not set instance of object". unless i'm mistaken, object in question lua, makes lua valid object reference. anyway, seeing these 2 solutions don't work, wondering if knows enough luainterface suggest alternative way same result. want effect of outputbuffer.add(lua.dostring(input));. way, lua command i've been using test print("test") - maybe print somehow returning console line instead of string, can't think of way return string lua.

i apologize if problem rambling or poorly explained - tried concise possible, it's kind of niche issue , don't know how else explain it, really. oh, , did try google, , browsed 65 or luainterface questions on stack overflow, i'm 95% sure i've done due diligence before asking question. luainterface not well-known of tool, guess.

object reference not set instance of object c#'s way of saying "something null , shouldn't be."

in case, dostring returning null, null.tostring() raising exception. try outputbuffer.add(convert.tostring(lua.dostring(input)[0])) if want convert string without throwing on nulls.

i haven't used either luainterface or nlua, i'd guess return string you'd have execute return "test" lua command.


Comments

Popular posts from this blog

Issues changing the value of an element in an array in matlab -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

vb.net - Alternative to the T-SQL AS keyword -