Commit Graph

51 Commits

Author SHA1 Message Date
Nathan Craddock
64ac44fb29
refactor: rename functions from aux* to *Aux
It makes things more clear when Aux is a suffix rather than a prefix.
2022-06-06 09:28:35 -06:00
Nathan Craddock
f619696f3c
docs: add more details on API wrapper 2022-06-06 09:20:15 -06:00
Nathan Craddock
5fa582d886
docs: update docs on tointegerx and tonumberx 2022-06-05 00:26:18 -06:00
Nathan Craddock
f5484c6c4a
add luazig.wrap() function
Adds a new function for wrapping various values to make it easier to
interact with the API. For example, one wrapper accepts a ZigFunction
and returns a Lua.CFunction wrapper around it.

Also adds a test for calling a Zig function from Lua
2022-06-05 00:22:36 -06:00
Nathan Craddock
3f6cfc0b09
fix: use Integer type for pushInteger
wrong parameter type used
2022-06-05 00:22:12 -06:00
Nathan Craddock
ffef22bc66
tests: add stack manipulation test
Adds a test that uses rotate, remove, insert, replace, copy, and
set/getTop to ensure those functions work. Updates a few functions that
couldn't be translated from macros.
2022-06-04 20:17:54 -06:00
Nathan Craddock
cd4f3a3093
refactor: return errors for toNumberX and toIntegerX
It is more Zig-like to return an error rather than use a return
parameter.
2022-06-04 19:46:08 -06:00
Nathan Craddock
41d17c39fd
refactor: use try instead of catch unreachable
This is effectively the same in a test. The catch unreachable is a bit
more explicit in that we assume it will not fail, but try is a bit
shorter
2022-06-04 19:38:17 -06:00
Nathan Craddock
d2bf84c262
tests: add tests for checkStack and auxCheckStack
Use an error union with void rather than a boolean for a more zig-like
interface for failure states.
2022-06-04 19:33:18 -06:00
Nathan Craddock
ebe925f769
tests: add a test for execution of strings
Tests pCall and loadString

Perhaps we need a version of pCall with all args default to 0 because
that's kind of annoying.. time will tell if this is common practice.
2022-06-04 14:42:39 -06:00
Nathan Craddock
ad1b4726d4
docs: update library documentation with examples 2022-06-03 19:50:57 -06:00
Nathan Craddock
b766c278b8
docs: note on toString 2022-06-03 19:30:27 -06:00
Nathan Craddock
4211c5a299
api: remove toLString()
There is no reason to have both toString() and toLString() when in Zig
we can get the length encoded in the slice type. Perhaps someone in the
future will raise a reason to have a separation with these functions. If
so, it is trivial to bring it back.
2022-06-03 19:25:53 -06:00
Nathan Craddock
25b43c15c9
update loadString to return errors
Return errors rather than an int to enforce checking
2022-06-03 19:14:01 -06:00
Nathan Craddock
559d090663
refactor: use Zig errors for pCall status codes
This enforces checking the error, and is a much more clean
implementation. This will likely be used for all such functions that can
return a status of LUA_OK or some error.
2022-06-03 18:55:32 -06:00
Nathan Craddock
2fa42a7877
fix: extra parameter on toString 2022-06-03 18:29:11 -06:00
Nathan Craddock
f94e5952d1
fix: Lua.pcall
Fixes KFunction to have a nullable ptr, and a few arguments that weren't
right
2022-06-03 18:29:07 -06:00
Nathan Craddock
43adb91067
cleanup: rearrange structs and update documentation
Move Lua.Buffer to the global scope because it isn't strictly tied
to the Lua state (though it maintains a copy internally afaik).
2022-06-03 16:54:01 -06:00
Nathan Craddock
6e882bc259
docs: update status 2022-06-03 16:45:28 -06:00
Nathan Craddock
7a76f735af
api: finish adding all functions, types, and constants
The api coverage is now complete, in the sense that all identifiers are
listed.

However, only a tiny tiny fraction is actually tested. There are likely
still many bugs to catch, but now we are in a position to fix and refine
this new Zig API.
2022-06-03 16:37:24 -06:00
Nathan Craddock
7e814242dc
add more constants and auxlib functions
Nearly there! 93% complete!

There are likely a lot of errors, but getting everything in the library
first makes it easier to write tests and debug as I go.
2022-06-03 14:45:11 -06:00
Nathan Craddock
9bc8f32b53
docs: update api coverage 2022-06-03 12:06:29 -06:00
Nathan Craddock
ebc4974549
auxlib: add all lua_Buffer functions
Adds all buffer functions wrapped in a struct to make the API easier to
use
2022-06-03 12:02:24 -06:00
Nathan Craddock
1d6821d509
add debug interface functions 2022-06-03 11:14:00 -06:00
Nathan Craddock
3e03c8953c
cleanup: rename c.lua_State -> LuaState
This makes types more readable
2022-06-03 10:33:26 -06:00
Nathan Craddock
597fa4a965
docs: update status 2022-06-02 22:22:57 -06:00
Nathan Craddock
ef411e74bc
finished wrapping main api functions
Still need to do the debug interface, the auxiliary library, and
remaining constants. Getting close though!
2022-06-02 22:21:50 -06:00
Nathan Craddock
f719e0b9f9
Close to 60% of api coverage now! 2022-06-02 22:09:23 -06:00
Nathan Craddock
f71e7aea12
docs: update readme to add new param in build.link function 2022-06-02 19:43:38 -06:00
Nathan Craddock
66d457d282
build: add new option to define LUA_USE_APICHECK
Adds an options struct to the public link function used to enable Lua
api argument checks. This will be enabled in debug builds only!
2022-06-02 19:41:57 -06:00
Nathan Craddock
dd41779537
add more functions (51%)
Still no tests, but will be added once the API is fully wrapped
2022-06-02 19:32:57 -06:00
Nathan Craddock
b28fc53c9a
docs: update status 2022-06-02 17:29:34 -06:00
Nathan Craddock
4bb120970f
add a few more constants 2022-06-02 17:28:37 -06:00
Nathan Craddock
48eed08757
cleanup: rename f64 -> Number
Use the internal Lua name for consistency
2022-06-02 17:17:56 -06:00
Nathan Craddock
7ca2b17e0f
cleanup: rename i64 -> Integer
Use the name of the internal Lua type for consistency
2022-06-02 17:15:39 -06:00
Nathan Craddock
0575d6e3f0
add a large chunk of functions (untested)
Just adds a large portion of the Lua API to Zig. Testing will come later
:)
2022-06-02 17:10:38 -06:00
Nathan Craddock
ed6a5906b6
docs: add readme.md and docs.md 2022-06-02 16:03:25 -06:00
Nathan Craddock
73588dcdac
rename zlua -> ziglua
It makes sense to make the library more discoverable even if zlua is a
simpler name.
2022-06-02 16:01:41 -06:00
Nathan Craddock
d760af7c46
tests: add tests for Lua.typeOf
Adds the beginnings of tests. There are some missing types, but those
will be gotten to eventually.
2022-06-01 21:04:48 -06:00
Nathan Craddock
419cdd787c
add type and typename functions
Because type is a Zig primitive, this adds typeOf as a workaround.
2022-06-01 20:33:14 -06:00
Nathan Craddock
68dedb550a
add remaining lua_to* functions
Again, not yet tested, but added the definitions. Now that all these
functions are done it will be easier to add tests (hard to test these
functions in isolation).
2022-06-01 19:56:37 -06:00
Nathan Craddock
0e7e3da07d
add lua_is* functions
Adds function definitions for all lua_is* functions. Not all are tested,
but will be soon.
2022-06-01 19:34:34 -06:00
Nathan Craddock
f05498164d
fix: use != 0 rather than == 1
Booleans are guaranteed to use 0 for false, but not so for 1, so it is
safer to check != 0 in returns from Lua.
2022-06-01 19:12:34 -06:00
Nathan Craddock
3a34c88ac4
cleanup: reorder types into own section
Declare all types in a section to make it easier to find them

Also renames AllocFn -> AllocFunction to make it more consistent with
CFunction (which did not look good as CFn).
2022-06-01 19:06:05 -06:00
Nathan Craddock
7495530f03
add all lua_push* functions
Not all are functional yet, but at least the definitions are there
2022-06-01 19:01:10 -06:00
Nathan Craddock
7090df6e24
add lua_arith and test
Adds Lua.arith for mathematical operations on the stack. Includes a test
where each operator is used at least once. The Zig wrapper uses an enum
to ensure no invalid operators are attempted.

A few other functions are included as needed for testing, but will be
tested individually later on.
2022-06-01 15:51:56 -06:00
Nathan Craddock
e49441220a
fix: prefix openLibs with aux
This is technically an auxiliary library based on its naming convention
2022-05-31 21:27:14 -06:00
Nathan Craddock
72b461992c
fix: allow newState data to be null
The pointer passed to lua_newstate is nullable
2022-05-31 21:18:04 -06:00
Nathan Craddock
1188fe6466
rename LICENSE -> license
I just like lowercase better :)
2022-05-31 21:08:16 -06:00
Nathan Craddock
6e178770c1
add standard library opening functions
Exposes the luaopen_* and luaL_openlibs. Also adds a Ziggified wrapper
function that takes a packed struct as input to specify which libs to
load.

After looking at rlua (a rust lua library) and the lua reference manual,
it seems that these library loading functions have the possibility of
failure. Not sure how to address this yet, but have left a todo.
2022-05-31 20:04:13 -06:00