LUA Development Environment

Hello all.

I am yet another one here who can’t figure out how to get a dev environment working for Lua.

Excluding vscode for now, I started basic. I installed Lua for Windows:

Perfect. All is well. I downloaded the ST libs and extracted them to C:\lualibs\lua_libs-api_v9. So far so good.

I set my LUA_PATH to C:\lualibs\lua_libs-api_v9?.lua;C:\lualibs\lua_libs-api_v9?\init.lua;.?\init.lua; as this is what the getting-started pages told me to do. Looks good to me.

I type in “lua” to enter the lua console. I can issue various commands. I try a few print commands and they work. Ok, good.

I look at the very first line of hello-world\src\init.lua file. It says this:

local capabilities = require “st.capabilities”

So I type this in, and I get this:

> local capabilities = require “st.capabilities”
error loading module ‘st.utils’ from file ‘C:\lualibs\lua_libs-api_v9\st\utils.lua’:
C:\lualibs\lua_libs-api_v9\st\utils.lua:684: ‘)’ expected near ‘&’
stack traceback:
[C]: ?
[C]: in function ‘require’
C:\lualibs\lua_libs-api_v9\st\capabilities\init.lua:14: in main chunk
[C]: in function ‘require’
stdin:1: in main chunk
[C]: ?

Ok, so what very basic everybody-knows-this-except-for-you-so-nobody-mentions-it thing am I missing here? It seems the LUA_PATH is being respected to some degree. Are there other libraries I need to load? If I remove the functions/offending lines in utils.lua that it references, I can get it to work and load and at least get past that line.

UPDATE: While my problem above still remains, after struggling with the array of kinda-sorta documented vscode/extension settings, I am able to get past that line of code in Visual Studio Code when I step through and debug. I had to add:

{
“lua.debug.settings.path”: “C:\lualibs\lua_libs-api_v9\?.lua;C:\lualibs\lua_libs-api_v9\?\init.lua;.\?\init.lua;”
}

to my .vscode/settings.json file. Who knew.

Anyway, it occurred to me that perhaps a SmartThings Edge driver isn’t MEANT to be run/executed locally. Maybe I made the incorrect assumption that I should be able to run and debug and step through my code (minus Zwave and Zigbee, of course). If this is the case, what do developers typically do during their iterative coding/debugging/testing iterative process? Is there some sort of remote debugging bridge available to debug through the hub in real time? Is there a less painful way than always deploying driver code via the ST CLI every single time?

Thanks!

I’ve not installed a Lua development environment as I can meet my limited Edge requirements with live testing, but I believe your starting point should be version 5.3 of Lua. Don’t get anything earlier or later than that.

1 Like

Ah ok, right. Thanks.

Though, on Windows, there doesn’t seem to be a clear path to update wholly to 5.4.x to Lua. Some reddit posts are quite discouraging:

"Welcome to Lua. :slight_smile:

Third party Lua libraries are a clusterfuck at best, totally broken at worst, and extremely slim pickings in either case."

Given that, I may choose to proceed with using LUA on WSL and forgetting about any sort of modern development environment.

How are others here working through their classic development cycle of iteratively coding/debugging/testing their stuff in a non-suicidal way? None of the scattered “getting started” pages seem to touch on that.

Apparently Lua 5.4 is a no go area with ST. It has to be 5.3.

That wouldn’t surprise me in the slightest. I’ve seen a Lua library with a bug that seemed familiar from a C library nearly forty years ago. However do you anticipate needing much in the way of third party libraries beyond those in the hub firmware?

Might make sense for the OP to download the ST Lua libraries and see what is necessary to run on the hub.

I downloaded the ST Lua libraries and I can deploy and run a sample hello-world on the hub. This is OK.

So really, now, I just want to play around with hello-world and do something simple like make a http POST call somewhere when this sample hello-world light is turned on. Instead of repeatedly coding and deploying to the hub and reading log files, I would like to just run my little routine locally, just to make sure I got my code right.

To do this, I see that I cannot simply require(“socket”) as it blows up here:

local socket = _envlibrequire(“socket”)

in integration_test\init.lua.

So now I have been messing around with LuaRocks to install a separate LuaSocket library, except that LuaRocks just plain sucks on Windows, and anything beyond Lua 5.1 just plain sucks to try to get working on Windows in any reasonable way.

So my next step, unless persuaded otherwise, is to go alll WSL and old-school command line to do my Lua development. I now see that I can use VS Code to connect WSL, so that might be the way to go.

Ok, thanks for the responses.

I’ve gotten far enough to make things happen with VSCode and WSL with a hacky-enough way to test LAN devices locally.

1 Like

Hi,
I am trying to do the same, I started with windows and now I have installed it on linux.
Although I have the API downloaded and added to the LUA_PATH, I can’t get the require “st.*” to work when launching a debug (I use LuaPanda and LuaHelp).
What VSCode extensions are you using?
How do you debug?
Thanks!

Are you using Visual Studio Code? I’m using that with WSL.

In the Lua Runtime Path setting, I include the lua_libs-api-v9 directory and that allows me to require “st.*”.

I am using Lua Runtime Version 5.3.

I can only debug locally when using LAN communications (naturally you can’t debug zwave or zigbee locally), and in doing so I replace:

local cosock = require “cosock”
local socket = require “cosock.socket”

with:

local socket = require “socket”.

I have these three extensions loaded:

image

I still assert that it’s a wonky language with weird syntax (why did SmartThings ever choose this?) and developing against it is a whack-job hacky effort at best.