Commit Graph

100 Commits

Author SHA1 Message Date
Nathan Craddock
0b728f9175
refactor: remove toNumberX and toIntegerX
Removes these functions in favor of toNumber and toInteger. These
remaining functions error if the value cannot be returned as a number.

This makes the API safer, while also being a bit more cumbersome. But it
is better to be explicit than use the old toNumber and not know it
returns 0 silently on fail.
2022-06-19 10:35:08 -06:00
Nathan Craddock
5ac473ded2
refactor: rename KContext -> Context 2022-06-18 22:28:22 -06:00
Nathan Craddock
4ce0da4919
docs: update status 2022-06-18 22:25:55 -06:00
Nathan Craddock
8398b38e83
refactor: accept a slice in pushString
Typically the strings pushed are from Zig so the lengths will be known
2022-06-18 22:22:42 -06:00
Nathan Craddock
566d775631
refactor: remove uses of std.mem.span
This can be used by the caller in cases where the length is needed
2022-06-18 22:13:54 -06:00
Nathan Craddock
db41f7582d
refactor: change toString to toBytes
The Lua API has the concept of lstrings (length strings). These are used
when the contents may contain zeroes, or when it is useful to know the
length. Because this data is not necessarily a string, ziglua has
renamed these lstring functions to bytes functions.

The toString function returns a zero-terminated many item pointer which
is useful when you know the data is not zero-terminated.
2022-06-18 22:05:21 -06:00
Nathan Craddock
21de06cb4e
refactor: tidy return values and cleanup TODOs 2022-06-18 21:52:22 -06:00
Nathan Craddock
7e50803c3f
tests: finish main library tests!
The main Lua API library is tested! The tests are very surface level,
but do provide a measure of security against changes now.
2022-06-18 21:24:04 -06:00
Nathan Craddock
07580a1ec4
tests: move tests to a separate source file
The file was getting very long so this makes things a bit more tidy
2022-06-18 16:38:42 -06:00
Nathan Craddock
fc58e1f7d5
tests: add many tests 2022-06-18 16:24:46 -06:00
Nathan Craddock
087033a6d8
tests: add more to table tests 2022-06-18 13:46:05 -06:00
Nathan Craddock
f55b6d5dea
add opaqueCast helper function
Adds a function that makes it a bit neater to cast opaque pointers from
the API.
2022-06-18 13:45:51 -06:00
Nathan Craddock
3f66cf105d
tests: add warning and setWarnF tests
Test that the warning handler works
2022-06-16 21:53:48 -06:00
Nathan Craddock
a027e21e1b
tests: add dump and load test 2022-06-16 21:46:56 -06:00
Nathan Craddock
196d7c7dfb
tests: add status test 2022-06-15 22:04:05 -06:00
Nathan Craddock
a596dc10fc
tests: rawEqual 2022-06-15 21:59:54 -06:00
Nathan Craddock
a9102df0e6
tests: various tests
Value conversion, table access and creation
2022-06-15 21:59:28 -06:00
Nathan Craddock
3157d5c123
tests: add a table access test
Exercises various table functions in the API
2022-06-12 15:23:08 -06:00
Nathan Craddock
09193ca5e6
cleanup: formatting 2022-06-11 22:10:35 -06:00
Nathan Craddock
48d51eb974
tests: add test for len 2022-06-11 22:10:16 -06:00
Nathan Craddock
1f362beafe
tests: add getExtraSpace test 2022-06-11 22:08:08 -06:00
Nathan Craddock
db385a43d3
tests: garbage collection (gc)
Tests the gc function with all of it's variants
2022-06-11 21:48:11 -06:00
Nathan Craddock
d01c34974b
tests: add concat test 2022-06-11 21:08:54 -06:00
Nathan Craddock
8ea8244dd0
tests: add compare test 2022-06-11 21:06:47 -06:00
Nathan Craddock
7ec1446024
tests: add atPanic test
The test only exercises the function because a panic will use longjmp
2022-06-11 21:01:36 -06:00
Nathan Craddock
d8f0238bd7
fix: pass lua pointer to all wrap functions
Using the pointer is smaller than the size of the full struct
2022-06-11 21:01:11 -06:00
Nathan Craddock
0fa25e79a0
docs: fix example code 2022-06-11 16:46:01 -06:00
Nathan Craddock
f9a62e70da
docs: update status, add example code, and describe differences 2022-06-11 16:44:53 -06:00
Nathan Craddock
b28ebe5afa
tests: add more is* and push* function tests
Adds more tests to verify that the is and push functions work for adding
and checking values on the stack.
2022-06-11 16:22:44 -06:00
Nathan Craddock
0ea17a6fbc
tests: add setFuncs and newLib tests
The luaL_setfuncs function (macro) expects a C array so it can calculate
sizes with sizeof(). In Zig as a function it would be awkward to pass a
null-terminated array of FnReg values.

So we make things easier by just rewriting the auxlib function in Zig,
which has the benefit of accepting a slice rather than an array.

Adds a test to ensure it works.
2022-06-11 16:08:37 -06:00
Nathan Craddock
7d1b3870b0
refactor: rename k -> cont
Use the word "cont" rather than "k" for continuations. This makes the
API a bit more clear, and only changes a few functions
2022-06-11 14:54:53 -06:00
Nathan Craddock
e2c9a7b46b
refactor: unify and simplify function type names
Rather than *Function in the names, use *Fn to make the names shorter.
This also adds the suffix Fn to any function type names that were
missing it.
2022-06-11 14:51:40 -06:00
Nathan Craddock
b22eea0a4a
tests: add test referencing all unused functions
This test makes it easy to confirm the correct signatures for all
functions. All functions have been checked and fixed at this point, and
in theory work just fine.

So "technically" 100% test coverage, but the functions should be used
before being really safe.
2022-06-11 14:38:51 -06:00
Nathan Craddock
23222717cc
tests: add global table and package tests
Adds tests that load the global table (_G) and inspect values in it. In
order to make this simple, the standard library packages are inspected.

This test led to discovering that the Lua.open() function wasn't working
properly as a replacement for openlibs(). Now it properly uses requireF
to load the desired standard library functions.

The various open* functions are still included, but are likely not very
useful in most common situations.
2022-06-10 22:16:43 -06:00
Nathan Craddock
564d63164d
tests: add allocator function tests
Test the setAllocF and getAllocF functions
2022-06-10 21:28:08 -06:00
Nathan Craddock
1fe4f342a6
cleanup: style 2022-06-10 21:22:46 -06:00
Nathan Craddock
b9ccd7b54e
tests: Lua Buffers
Adds a test to ensure each of the luaL_Buffer functions work. In
experimenting with this, I have found the Buffer code to be very touchy.
If you don't use it correctly things will break badly. Perhaps there is
something that can be added in the Zig layer for safety.

Requires to initialize a Buffer variable before calling init because the
structure keeps a pointer to an internal array so the struct cannot be
passed or returned by value.
2022-06-10 21:05:46 -06:00
Nathan Craddock
f83eed4ced
refactor: move all types outside of Lua struct
This makes code cleaner (no need to prefix with Lua), and it makes
sense, as these constants are not necessarily associated with the Lua
state struct itself.
2022-06-07 21:23:11 -06:00
Nathan Craddock
31ebb27710
refactor: rename pCall -> protectedCall
Zig intends to communicate intent precisely. So let's make the function
name more clear.
2022-06-07 09:10:40 -06:00
Nathan Craddock
4323f0fbc2
tests: test pushString 2022-06-06 21:37:31 -06:00
Nathan Craddock
2a1d25b49a
docs: update with more info on the ziglua structure 2022-06-06 21:30:40 -06:00
Nathan Craddock
6bf8eb8fe0
cleanup: remove pushLiteral
There is "literally" no reason to add this function!
2022-06-06 21:14:36 -06:00
Nathan Craddock
5b831b9374
refactor: various error returns
Cleans up returns for various (unused) functions by adding zig errors
2022-06-06 21:07:13 -06:00
Nathan Craddock
f8534b4e59
refactor: return an enum for status
returns an enum for Lua.status rather than a plain int.
2022-06-06 20:53:17 -06:00
Nathan Craddock
10c31f438c
refactor: add new superset Error union
Creates a superset to make sure error types are organized throughout the
API
2022-06-06 20:40:37 -06:00
Nathan Craddock
b0ded46ef6
use Zig errors for loadFileX 2022-06-06 20:30:11 -06:00
Nathan Craddock
1c1aa58161
use Zig errors for load return values
The function can error, so use Zig errors to indicate that
2022-06-06 20:28:16 -06:00
Nathan Craddock
705e764fe8
fix: make the gc function return i32
The gc function can return many different values depending on the type
of action given.
2022-06-06 20:25:48 -06:00
Nathan Craddock
3d29769f0b
tests: add version test 2022-06-06 19:17:05 -06:00
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