Failing that, you're looking at writing the support code you need in C or C++ (or some other language that can created Lua-loadable shared library), which is a whole other ball of wax if you don't already know such a language.Īnother problem you're going to face, assuming you've somehow acquired the ability to create TCP sessions, is. You could then check out something like LuaSocket and see if it's asynchronous enough to work for you. If those are supported, you can do anything you want. ![]() However, if Mudlet's Lua interpreter is not sandboxed, it may include the standard library routines require or package.loadlib, which will let you load external Lua modules. If the Mudlet Lua API doesn't expose a communication layer, you're pretty much done, as far as implementing this in Lua goes. Lua has no networking APIs in it's standard library. I don't even know if I've explained my problem completely, but I'll gladly supply more information if needed, but would anyone with Lua or similar experience know how I can get started trying to make a communication protocol? Now, the hard part is that I'm a bit of a new programmer, and even then I've never dabbled with a "real" language, just scripting business. I can't just set up a loop and have whatever script I write keep listening for network responses, because while it's running the program grinds to a halt. Now, here's the tricky part: Mudlet is single-threaded. It's much like the way World of Warcraft AddOns can talk to eachother in a hidden channel, but in this case, I have to implement said channel myself. Now, what I'm attempting to do here is probably a bit beyond my skill level, but I still want to give it a shot: I'm attempting to create a framework for scripts to talk to the scripts of other users in Lua. It's implemented in another language, but uses a Lua environment so the user can write scripts that enhance your playing of any given game. You can use the Lua API to bind it, or directly access it via LuaJIT's FFI (recommended).I'm using an application called Mudlet, which is basically a multi-OS client that allows you to connect to MUD/MUSH/MUX/whatever games (or any other text-based medium, I suppose). It also abstracts operating system specific details, much like LuaSocket does. It provides the perfect mix between TCP and UDP: reliable when desired, unreliable otherwise. (LuaJIT supports callbacks if the API requires it however, there is a signficant performance cost compared to polling from Lua to C.) LuaJIT + ENetĮNet is a great library. As for Linux and the rest, look at tutorials for C or the source of LuaSocket and translate them to LuaJIT FFI operations. He's had some very interesting adventures with LuaJIT and Windows development. Lua Lanes would be useful for this as well.įor Windows, I suggest taking a look at William Adam's blog. LuaJIT's FFI library makes this possible from pure Lua. If you're a little masochistic, you can try implementing a socket library from scratch. The results are promising, though you should definitely refactor my example code if you derive from it. It relies on Lua Lanes 3.4.0 ( GitHub repo) and a patched LuaSocket 2.0.2 ( source, patch, blog post re' patch) I've made a simple example of this, available here. This is probably the best solution to your problem. Then, you use a linda to send the data to the main thread for processing. ![]() This allows you to instantly read the data from the socket and into a buffer. Same as the above method, but the socket exists in another lane (a lightweight Lua state in another thread) made using Lua Lanes ( latest source). Lua51/LuaJIT + LuaSocket + Lua Lanes (Recommended) I would suggest using a coroutine scheduler for the non-blocking version, to allow other parts of the program to continue executing without causing too much delay. Non-blocking: call lect with a timeout argument of 0, and use sock:settimeout(0) on the socket you're reading from. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |