This isn’t really a bug, but would be great to address for developers. I have some unit tests that I need to run outside of an actual integration test suite. These are for utility libraries which include some of the ST libraries. I am unable to use the ST libs because they are looking for _envlibrequire
which doesn’t exist.
This is one example from socket/init.lua
local socket = _envlibrequire("socket")
This function is defined in integration_test/init.lua
local envlibs = {
datastore = datastore,
devices = mock_devices_api,
log = log,
socket = socket,
--ssl = socket.ssl, -- unused
timer = timer,
--util.call_rpc_method = call_rpc_method.lua, -- unused
--util.stringify_and_join = stringify_and_join, -- unused
json = dkjson,
}
function _envlibrequire(module)
return envlibs[module]
end
It would be great if the libs could be included in standalone scripts. I wasn’t even trying to run the code outside of ST. I just have a lib file of my own that is requiring cosock
for one part and it won’t load it. I get this error.
lua: ...ocal/lib/smartthings/lua_libs-api_v0/socket/init.lua:12: attempt to call global '_envlibrequire' (a nil value)
stack traceback:
...ocal/lib/smartthings/lua_libs-api_v0/socket/init.lua:12: in main chunk
[C]: in function 'require'
...al/lib/smartthings/lua_libs-api_v0/cosock/socket.lua:14: in main chunk
[C]: in function 'require'
...usr/local/lib/smartthings/lua_libs-api_v0/cosock.lua:1: in main chunk
[C]: in function 'require'
test.lua:1: in main chunk
[C]: ?
Edit:
Here is my workaround in my own lib:
local socket
if _envlibrequire ~= nil then
socket = require 'cosock.socket'
else
socket = require 'socket'
end