Page 1 of 1
LuaSocket
Posted: Sat Apr 27, 2024 2:43 pm
by MehdiZangenehBar
Is it possible to add LuaSocket module to the Moho?
Re: LuaSocket
Posted: Sun Apr 28, 2024 9:39 pm
by SimplSam
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.
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)
* 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")
Re: LuaSocket
Posted: Mon Apr 29, 2024 12:20 pm
by MehdiZangenehBar
Thank You Sam! I will check it out...
Re: LuaSocket
Posted: Mon Apr 29, 2024 12:50 pm
by MehdiZangenehBar
Your solution works great!
My idea is to create an external app to cominucate with Moho using localhost, do you think it works?