LuaSocket
Moderators: Víctor Paredes, Belgarath, slowtiger
- MehdiZangenehBar
- Posts: 114
- Joined: Wed Feb 07, 2024 7:17 pm
- Contact:
LuaSocket
Is it possible to add LuaSocket module to the Moho?
Re: LuaSocket
This is from a previous discussions:
I did find an out-of-the-box Windows binary 5.4 LuaSocket implementation that worked: https://github.com/alain-riedinger/luasocket. Release: https://github.com/alain-riedinger/luas ... /3.0-5.4.3
This just requires updates to path and cpath to point at the installed-to directory (scriptresources in my case), and then use.
...
Connection Test:
...
Simple HTTP Request *:
* Note: There is a slight issue with this shipped LuaSockets build (which is 3 years old - and contains an old compatibility buglet) when using HTTP and Lua 5.3/5.4. (see: https://github.com/lunarmodules/luasocket/issues/331). The quick fix is to: Update/Replace all receive() calls in http.lua and tp.lua with receive("*l")
I did find an out-of-the-box Windows binary 5.4 LuaSocket implementation that worked: https://github.com/alain-riedinger/luasocket. Release: https://github.com/alain-riedinger/luas ... /3.0-5.4.3
This just requires updates to path and cpath to point at the installed-to directory (scriptresources in my case), and then use.
Code: Select all
package.path = package.path .. ";" .. moho:UserAppDir() .. "/scripts/scriptresources/?.lua;"
package.cpath = package.cpath .. ";" .. moho:UserAppDir() .. "/scripts/scriptresources/?.dll;"
Connection Test:
Code: Select all
local socket = require "socket"
local connection = socket.tcp()
connection:settimeout(1000)
local result = connection:connect("ifconfig.co", 80)
connection:close()
print("result: ", result)
Simple HTTP Request *:
Code: Select all
local http = require("socket.http")
local response = http.request("https://ifconfig.co/json")
print("response: ", response)
Moho 14.3 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.3 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam
Sam
Moho 14.3 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam
Sam
- MehdiZangenehBar
- Posts: 114
- Joined: Wed Feb 07, 2024 7:17 pm
- Contact:
Re: LuaSocket
Thank You Sam! I will check it out...
- MehdiZangenehBar
- Posts: 114
- Joined: Wed Feb 07, 2024 7:17 pm
- Contact:
Re: LuaSocket
Your solution works great!
My idea is to create an external app to cominucate with Moho using localhost, do you think it works?
My idea is to create an external app to cominucate with Moho using localhost, do you think it works?
- MehdiZangenehBar
- Posts: 114
- Joined: Wed Feb 07, 2024 7:17 pm
- Contact:
Re: LuaSocket
Sam, would you please tell me where (in which file) , I can set those path and cpath settings?SimplSam wrote: ↑Sun Apr 28, 2024 9:39 pmCode: Select all
package.path = package.path .. ";" .. moho:UserAppDir() .. "/scripts/scriptresources/?.lua;" package.cpath = package.cpath .. ";" .. moho:UserAppDir() .. "/scripts/scriptresources/?.dll;"