LuaSocket

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
MehdiZangenehBar
Posts: 50
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

LuaSocket

Post by MehdiZangenehBar »

Is it possible to add LuaSocket module to the Moho?
User avatar
SimplSam
Posts: 1060
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: LuaSocket

Post 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")
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
MehdiZangenehBar
Posts: 50
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Re: LuaSocket

Post by MehdiZangenehBar »

Thank You Sam! I will check it out...
User avatar
MehdiZangenehBar
Posts: 50
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Re: LuaSocket

Post 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?
Post Reply