0

I've recently added NLUA support to my application, with the goal of allowing easy editing of functionality. Perhaps a quick explanation.

I'm making a simple game, in the style of DarkSigns and other "hacking" simulators. I wanted to allow for scripting to be used for both myself and my players. I decided to use NLUA to provide this. The base application is written in c# using WPF and caliburn.micro.

SO i have a simulated console which is actually a textbox for input and a listview for the console ouput, I have a command structure that allows for commands to be typed in and run, including the "connect" command to access a (ingame) IP address, this includes a port which is tied to a script. So connecting to 1.2.3.4 port 25 will run the "port25.lua" script.

All that works fine, however i realized that i have no way to direct input into these scripts, any LUA that calls io.read() won't actually wait for input and so fails.

So i'm looking at how to solve this, unfortunalty NLUA documentation seems to be pretty thin on the ground, I'm aware this is made more complex by the fact I'm not using an actual console and just simulating one.

Would what i want even be possible? If so how could I redirect NLUA io.read()to my textbox (if possible) or is there another solution?

Or would moving away from NLUA into another scripting addition be a better solution?

Thanks for your time.

Ben
  • 1,291
  • 2
  • 15
  • 36
  • You can pass parameters to LUA. So you can read the inputs from c# and then pass to LUA. See : https://www.lua.org/pil/25.3.html. – jdweng Dec 09 '16 at 10:22
  • http://stackoverflow.com/a/1815193/2858170 – Piglet Dec 09 '16 at 10:31
  • Piglet, I'm sorry that doesn't really help. I'm aware of io.read however as i mentioned it doesn't work when using it in the situation i described – Ben Dec 09 '16 at 10:37
  • If you have made custom console, you should not expect that Lua can work with it. Write your own functions in C# to read and write your console and expose them to Lua. – Egor Skriptunoff Dec 09 '16 at 11:41
  • @EgorSkriptunoff Ok, I guess i already knew that. Could you perhaps give some advise on how to write those functions. I've been trying to work it out all day and i'm at a loss on how to go about a read function (I already had write) that will work similar to console.readline – Ben Dec 09 '16 at 16:03
  • 1
    I don't consider using blocking Lua scripts as a good idea. It would be better to call Lua scripts as a short response to some events (for example, when a key was entered by a user). Think in "event-driven" style. – Egor Skriptunoff Dec 09 '16 at 16:50
  • Unfortunately that defeats the entire purpose i was using them for, So i guess i'll look for another scripting solution other than LUA – Ben Dec 10 '16 at 14:21
  • @jdweng Can you please help me with this question :https://stackoverflow.com/questions/48400700/how-to-use-json-methods-inside-lua-script-and-execute-lua-script-with-c – I Love Stackoverflow Jan 23 '18 at 12:23
  • @Ben did you figure out a solution to this? – Frank Hale Jul 07 '22 at 15:42

0 Answers0