Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/addition.carp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(load "https://github.com/carpentry-org/lua@0.1.0")
(load "https://github.com/carpentry-org/lua@0.2.0")

(Lua.setup "lua")

Expand Down
2 changes: 1 addition & 1 deletion examples/config.carp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(load "https://github.com/carpentry-org/lua@0.1.0")
(load "https://github.com/carpentry-org/lua@0.2.0")

(Lua.setup "lua")

Expand Down
2 changes: 1 addition & 1 deletion examples/errors.carp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(load "https://github.com/carpentry-org/lua@0.1.0")
(load "https://github.com/carpentry-org/lua@0.2.0")

(Lua.setup "lua")

Expand Down
2 changes: 1 addition & 1 deletion examples/tables.carp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(load "https://github.com/carpentry-org/lua@0.1.0")
(load "https://github.com/carpentry-org/lua@0.2.0")

(Lua.setup "lua")

Expand Down
16 changes: 11 additions & 5 deletions lua.carp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@
(doc %fn-name
"Set field `name` to `value` on the table at `index`. Handles the stack index shift from pushing the value internally.")
(defn %fn-name [lua index name value]
(do (%pusher lua value) (Lua.set-field lua (- index 1) (cstr name))))))))
(do
(%pusher lua value)
(Lua.set-field lua (if (< index 0) (- index 1) index) (cstr name))))))))

(defmacro luax--def-get-field [suffix type-const getter article type-article]
(let [fn-name (Symbol.concat ['get- suffix '-field])
Expand Down Expand Up @@ -416,7 +418,7 @@ stack unchanged.")
(do
(push-nil lua)
(let-do [count 0]
(while-do (/= 0 (next lua (- index 1)))
(while-do (/= 0 (next lua (if (< index 0) (- index 1) index)))
(set! count (+ count 1))
(pop lua 1))
count))))
Expand Down Expand Up @@ -780,9 +782,13 @@ call raises a Lua error.
%@pushes
(let [%result-sym (Lua.call %lua %nargs 1 0)]
(if (= %result-sym Lua.OK)
(Result.Success (%getter %lua -1))
(Result.Error
(String.from-cstr-or (Lua.to-string %lua -1) @"unknown error")))))))))
(let-do [res (%getter %lua -1)]
(Lua.pop %lua 1)
(Result.Success res))
(let-do [err (String.from-cstr-or (Lua.to-string %lua -1)
@"unknown error")]
(Lua.pop %lua 1)
(Result.Error err)))))))))

(doc make-table "Create a Lua table with the given fields and assign it to the
global `name`. Each field spec is `(field-name (push-expr))`, where the `lua`
Expand Down
Loading