LuaSocket question and one more thing

Posted by Ircria on Wed 09 Feb 2011 09:40 PM — 4 posts, 16,690 views.

#0
Two questions here. First, when I use LuaSocket, it tends to have a delay as the information is grabbed. I tried working around this with Coroutines, but that didn't seem to work. Is there any way to get rid of this delay?

Also, I was wondering about how MUSHclient includes the main lua file. Would there be any issues if I used luac to compile my script file into bytecode?

Thank you.
Australia Forum Administrator #1
I think the default in LuaSocket is to do "blocking" calls, hence your delay. Coroutines, per se, are not going to change that. It depends what you are trying to achieve, I think the library itself allows asynchronous IO, however it can be a little fiddly because MUSHclient itself has a "main loop" where it looks for incoming TCP data, and to have another point (in LuaSocket) where it also looks for TCP data is going to have two "choke points" so to speak.

Ircria said:

Also, I was wondering about how MUSHclient includes the main lua file. Would there be any issues if I used luac to compile my script file into bytecode?


It loads the main Lua file "the usual way". You can precompile it if you want. I just tested that and it worked OK. I'm not sure why you would bother, it makes changing scripts harder, and you don't save much time, but in principle you can do it.
#2
Mm. That makes sense. Thank you. Had a couple of other questions raised in that time.

When Note()ing before a luasocket call, it doesn't display the Note() in the buffer until after the socket function returns. Is there any way to get around this? Also, I was wondering if there was any way for my script to be alerted when the world connects/disconnects.

Thank you again.
Australia Forum Administrator #3
The redrawing of the output window is done once the script completes. Calling Repaint () after the Note might help. Otherwise try SetStatus and keep an eye on the status line.

As for the connect/disconnect add a function name to the scripting "World Events" connect/disconnect boxes. You will need a script file to be active, and then provide a suitable function (one that takes no arguments) to display messages or otherwise react.

In a plugin you can use a plugin callback to do a similar thing.