Skip to content

Commit

Permalink
chore(lua): add luacheck and fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Nov 4, 2024
1 parent 6fc8a15 commit 16562c0
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 28 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ jobs:
- uses: leafo/gh-actions-lua@v10
with:
luaVersion: '5.3'

- name: Setup LuaRocks
uses: leafo/[email protected]

- name: Install Luacheck
run: luarocks install luacheck

- run: luacheck .

# TODO: add ar-io-sdk e2e tests against lua code to be bundled on changes (e.g. create a new ant, publish it and validate it works with the sdk)
Expand Down
2 changes: 1 addition & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
allow_defined = true
exclude_files = {
"src/crypto",
"dist/",
}
globals = {
"Handlers",
Expand Down
6 changes: 1 addition & 5 deletions spec/setup.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package.path = "./src/?.lua;./src/common/?.lua;" .. package.path

_G.ao = {
send = function(obj)
send = function(_)
return true
end,
id = "test",
Expand All @@ -15,8 +15,4 @@ _G.Handlers = {
},
}

os.clock = function()
return 0
end

print("Setup global ao mocks successfully...")
2 changes: 1 addition & 1 deletion src/common/initialize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function initialize.initializeANTState(state)
end

local function findObject(array, key, value)
for i, object in ipairs(array) do
for _, object in ipairs(array) do
if object[key] == value then
return object
end
Expand Down
4 changes: 2 additions & 2 deletions src/common/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ local function escape_char(c)
return "\\" .. (escape_char_map[c] or string.format("u%04x", c:byte()))
end

local function encode_nil(val)
local function encode_nil()
return "null"
end

Expand Down Expand Up @@ -77,7 +77,7 @@ local function encode_table(val, stack)
error("invalid table: sparse array")
end
-- Encode
for i, v in ipairs(val) do
for _, v in ipairs(val) do
table.insert(res, encode(v, stack))
end
stack[val] = nil
Expand Down
6 changes: 3 additions & 3 deletions src/common/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,13 @@ function ant.init()
end)

Handlers.add(camel(ActionMap.Records), utils.hasMatchingTag("Action", ActionMap.Records), function(msg)
local records = records.getRecords()
local allRecords = records.getRecords()

-- Credit-Notice message template, that is sent to the Recipient of the transfer
local recordsNotice = {
Target = msg.From,
Action = "Records-Notice",
Data = records,
Data = allRecords,
}

-- Add forwarded tags to the records notice messages
Expand Down Expand Up @@ -515,7 +515,7 @@ function ant.init()
end

local srcCodeTxIdStatus, srcCodeTxIdResult = pcall(utils.validateArweaveId, srcCodeTxId)
if srcCodeTxIdStatus and not srcCodeTxIdStatus then
if srcCodeTxIdStatus and not srcCodeTxIdResult then
ao.send({
Target = msg.From,
Action = "Invalid-Evolve-Notice",
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local utils = { _version = "0.0.1" }
local function isArray(table)
if type(table) == "table" then
local maxIndex = 0
for k, v in pairs(table) do
for k, _ in pairs(table) do
if type(k) ~= "number" or k < 1 or math.floor(k) ~= k then
return false -- If there's a non-integer key, it's not an array
end
Expand Down
15 changes: 0 additions & 15 deletions src/process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,6 @@ function Send(msg)
_ao.send(msg)
return "message added to outbox"
end

function Spawn(module, msg)
if not msg then
msg = {}
end

_ao.spawn(module, msg)
return "spawn process request"
end

function Assign(assignment)
_ao.assign(assignment)
return "assignment added to outbox"
end

function Tab(msg)
local inputs = {}
for _, o in ipairs(msg.Tags) do
Expand Down

0 comments on commit 16562c0

Please sign in to comment.