0

I'm very lost with this matter, so sorry if I'm asking for something too obvious or something, but I've been trying to get some low level info about it and, for what I've seen till now, I wouldn't even know where to start...

Anyway, the case is I'm trying to develop a tool script in Lua that I'd like at some point could be able to do some very basic interaction with a webpage, e.g. for downloading/looking for updates and little more. I'm already aware Lua can't do any of this per se (even I think it totally should at this time of life, but that would be another discussion ), and the only ways I've read about pass for using external libraries/packages like LuaSocket or lua-http.

Well, besides all that external kind of stuff are far beyond my current capabilities in all the senses, how could I make them work anyway if I'm constrained to only can really do what the main app (Moho in this case, internally running Lua 5.2) allows me to do? Or as far as I know at least, because I remember at some point they added the possibility of extending some Lua possibilities by allowing access to a folder called modules where supposedly you could put your own libraries or whatever, not sure if even in form of DLLs, but besides that would also be another level to me, and there is zero documentation on that regard, once again I wouldn't even know where to start... Plus, if I'm going to have to build my own Lua compilation and include a lot of extra files, etc. for such a simple update checking feature... well, as much as I'd like its implementation, it simply could not worth all the mess.

So, once exposed, what do you think are really my changes of getting this super-basic internet interaction from my pure Lua script? Are really 0 as I'm afraid, or do you think I could not be considering other possible ways even if they were not the more efficient or recommendable?

Rai
  • 314
  • 1
  • 2
  • 9
  • LuaSocket should be included, but you are restricted to HTTP only afaik. Can you use LuaRocks? Using `luarocks install http` works for me flawless, without the need to add libraries myself. It should also work from within your plugins. – Luke100000 Oct 26 '22 at 10:47
  • When you say _included_ do you mean it should be already into the main application's embedded Lua 5.2 libraries? Because that would be great even if it's limited to HTTP (for now at least). But I'm not sure if I'm misunderstanding (probably ). Not sure what to say about LuaRocks because I'm still researching about it and there are a lot of concepts I'm still not getting since, although I've Lua installed and well configured in Windows, I've been always centered in basic Lua scripting usage inside the main app, so anything different than that it's like a whole new world of info [CONTINUED] – Rai Oct 26 '22 at 12:51
  • @Luke100000 But, I can see now `print(package.path ..'\n' .. package.cpath)` says: `C:\Program Files\Moho\?.lua;C:\Program Files\Moho\lua\?\init.lua;C:\Program Files\Moho\?.lua;C:\Program Files\Moho\?\init.lua;\?.lua'` `C:\Program Files\Moho\?.dll;C:\Program Files\Moho\loadall.dll;\?.dll;C:\Program Files\Moho\Resources\Support\Scripts\Modules\?.dll;C:\Moho\Scripts\Modules\?.dll` So _Modules_ folder does seem to be taken into account. Should that give me hope for simply can put e.g. _core.dll_, _socket.lua_, etc. into it and get everything working for anyone doing the same? Thanks, BTW – Rai Oct 26 '22 at 12:52
  • Yea, if you have the binaries it should also work, but lua-https seems to have quite some dependencies, that's why I recommend LuaRocks. In any case, if you do not need encryption take a look at Kulchenkos answer in https://stackoverflow.com/questions/24575504/send-get-to-website-with-lua. 3 lines to fetch a webpage, and afaik LuaSocket is always included. Notice that some modern servers do not allow an unsecure connection. – Luke100000 Oct 26 '22 at 13:33
  • @Luke100000 No luck... I've put some binaries I've found into the _Modules_ folder, but all I get by running Kulchenko's code are error messages like: `module 'socket.http' not found`, `no field package.preload['socket.http']`, `no file 'C:\Program Files\Moho\lua\socket\http.lua'` [etc...] `no file 'D:\Moho\Scripts\Modules\socket.dll'`. BUT I've the feeling I couldn't have the correct ones. Do you know where I could simply download them? Cause I've found [**these**](https://github.com/CristiFati/Prebuilt-Binaries/tree/master/LuaSocket), but they're for Lua5.4 and I assume I'd need the 5.2 ones – Rai Oct 26 '22 at 14:18
  • @Luke100000 Oh, and the exact version of the language that the program is using for the interpreter is **Lua 5.2.4**, BTW (just in case it matters, as I guess). – Rai Oct 26 '22 at 14:37
  • As a last update... Well, it seems I have somehow got rid of the pile of errors by also copying the binaries to a folder named "lua" in the installation directory of the program, BUT... Now I'm getting the following one: `error loading module 'socket.core' from file 'D:\Moho\Scripts\Modules\socket\core.dll'`. I've tried both, binaries 32 & 64 bit, with same result. Anyway I'm almost given up with this, since if the final user's going to've to deal with all the mess of copying files into the program's directory and everything... I don't think it's the way to go. Tho still hope there's a way... – Rai Oct 26 '22 at 16:19
  • Sorry, I missed the second line of the message after a colon: `%1 is not a valid Win32 application.` (Hence my try of using both 32 and 64 bit LuaSocket libraries that I could find with exactly the same outcome). – Rai Oct 26 '22 at 16:47
  • Hi @Ramon0 - Take a look at: https://love2d.org/wiki/Main_Page - Its Lua 5.1 and not sandboxed in any way until you do that by your self - But the best is: Windows / macOS / Linux (This includes Android) distribution - And beside all the Video/Audio Keyboard/Mouse/Touch and ```luasocket``` and ```enet``` Stuff it support also: Animations (Quads/Particlesystem/Physics) - And to edit the Scripts: nvim – koyaanisqatsi Oct 26 '22 at 18:11
  • Both, LÖVE and NeoVIM have LuaJIT (that uses Lua 5.1) – koyaanisqatsi Oct 26 '22 at 18:19
  • Thanks @koyaanisqatsi, I already knew about LÖVE (always kinda called my attention indeed) but I'm afraid I'm too tied to Moho at this point... I've always thought that I'd only jump to a game engine instead if it implemented a vector based graphics system, but I don't think that's going to happen anytime soon, again (Flash?). Or are you suggesting I can somehow get the LuaSocket binaries from it? Because I've been inquiring a bit and I don't really see the way... Not sure if that will even make any sense, but been as desperated as I am at this point I think I could end up trying anything – Rai Oct 26 '22 at 19:12
  • @koyaanisqatsi Or, on 2nd thoughts, you were suggesting I could try to use LÖVE for writing my tool from there (or the part having to do with web at least) and then somehow apply the possible achievements into my Moho scripts? I think that could make more sense than my 1st thought, but it make me think... First off, LÖVE seems to use Lua 5.1 and Moho internal interpreter uses Lua 5.2.4, and secondly, I'm not very confident it (assuming I can get the all dependencies from it to put them in my Moho/Modules folder) finally helps solving the errors I'm getting anyway. But I may lose nothing... – Rai Oct 27 '22 at 14:57
  • @Ramon - From my point of view Lua is as strong/weak as the Host. - Lua 5.4 Standalone can use the whole system including all its gizmos (so called help applications like free, df, type, cat, echo and so on) and all other installed applications. So with a none sandboxed Lua it is very easy to get a webpage for example. Since Lua do not interpret XML/HTML/CSS/JavaScript it is better to get a text file (*.txt) and that can also be anything to Lua. A very simple way to do this in Lua is one call to ```tfws = io.popen('wget -q -O- http://localhost/lua.txt'):read('*a')``` That saves it in: tfws – koyaanisqatsi Oct 29 '22 at 13:40
  • @koyaanisqatsi I couldn't agree more about your first statement... But the case is, unfortunately, what I'd want to do only has sense if done under the application itself, and that totally ties me to the internal Lua interpreter it has, so I guess I'm kinda screwed... – Rai Oct 29 '22 at 15:24
  • Plus, I just discovered it could be not only me but other Moho users also not being able to load modules within .dlls files for whatever reason, so it seems even I finally got the LuaSocket correct/working binaries for Lua 5.2.4 64-bit, I may not be able to make it work in any way after all due to this bug ([**HERE**](http://www.lostmarble.com/forum/viewtopic.php?t=33174) is the link for the record). So I'm afraid I'm forced to abandon this part of the idea for now as much as it hurt, because I already had a lot of hopes put on it... But thanks anyway, of course. – Rai Oct 29 '22 at 15:25

0 Answers0