Files
zeekay 91103511be Finish capnp->ZAP rebrand; vendor lunitx; decouple cjson; bump rockspec
Rename the Cap'n Proto Lua port to ZAP, brand-neutral throughout:
- capnp.lua -> zap.lua, capnp/ -> zap/, *.capnp -> *.zap, compiler bins
  capnpc-* -> zapc-*, schema/handwritten modules -> *_zap.lua. Zero
  capnp/Cap'n Proto leftovers in zap-native source/build (upstream-fork
  Kenton Varda copyright headers in proto/c++.zap and bin/schema.zap stay).
  Generated-code header and doc links point at github.com/zap-proto/lua and
  zap-proto.io.

Tests now run with no extra install:
- Vendor the lunitx test framework (Michael Roth / Doug Currie, MIT) under
  vendor/ (lunit, lunit.console, lunitx, lunitx.atexit). Its __gc atexit hook
  drives each test file under LuaJIT and exits nonzero on any failure.
- tests/run_tests.sh and test.sh are self-contained (set LUA_PATH incl
  vendor/), generate proto/example_zap.lua via the `zap` compiler when present,
  and skip 01/10 with a clear note (never a false pass) when it is absent.
  02-util and 03-compile are pure-Lua and always run.
- Verified under LuaJIT 2.1: 01(20) + 02(7) + 03(1) + 10(31) = 59 tests pass,
  0 failed; runner returns nonzero on an injected failure.

Decouple optional cjson so the runtime/compiler load under a bare LuaJIT:
- zap/compile.lua loads cjson lazily and only for debug logging (guarded by
  the debug flag); bin/zapc-llua makes the schema JSON dump optional.

Rockspec: bump lua-zap to 0.1.3-4, declare lua-cjson >= 2.1.0, and install the
vendored lunitx modules. .gitignore: scope the rockspec-pack ignore to repo
root so rockspec/ specs are tracked; ignore the `dump` test artifact.

TODO trimmed to the genuinely remaining items (AnyPointer set/decode, packed
serialization, schema_zap regeneration, multi-file compile, perf).
2026-06-20 00:12:16 -07:00

81 lines
1.8 KiB
C++

#include "example.zap.h"
#include <zap/message.h>
#include <zap/serialize-packed.h>
#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <kj/common.h>
void writeT1(int fd) {
::zap::MallocMessageBuilder message;
T1::Builder t1 = message.initRoot<T1>();
//::zap::List<Person>::Builder people = addressBook.initPeople(2);
t1.setI0(32);
t1.setI1(16);
t1.setB0(true);
t1.setI2(127);
t1.setB1(true);
t1.setI3(65536);
t1.setE0(::T1::EnumType1::ENUM3);
T1::T2::Builder t2 = t1.initS0();
t2.setF0(3.14);
t2.setF1(3.14159265358979);
::zap::List< ::int8_t>::Builder l0 = t1.initL0(2);
l0.set(0, 28);
l0.set(1, 29);
t1.setT0("hello");
const char *str = "\1\2\3\4\5\6\7";
t1.setD0(::zap::Data::Reader(reinterpret_cast<const ::zap::byte*>(str),
strlen(str)));
t1.setE1(::EnumType2::ENUM7);
//t1.setUi0(0xf0f0);
t1.setUi1(0x0f0f);
T1::G0::Builder g0 = t1.initG0();
g0.setUi2(0x12345678);
T1::U0::Builder u0 = t1.initU0();
T1::U0::Ug0::Builder ug0 = u0.initUg0();
ug0.setUgu0(32);
::zap::List< ::T1::T2>::Builder ls0 = t1.initLs0(2);
ls0[0].setF0(0.61803398875);
ls0[0].setF1(1.61803398875);
ls0[1].setF0(2.71828182846);
ls0[1].setF1(2.71828182846);
//auto o0 = t1.getO0().initAs< ::T1::U0 >();
//o0.setUv1();
//o0.set(0, 2);
::zap::List< ::zap::Text>::Builder lt0 = t1.initLt0(2);
lt0.set(0, "foo");
lt0.set(1, "bar");
writeMessageToFd(fd, message);
}
void readT1(int fd) {
::zap::StreamFdMessageReader message(fd);
T1::Reader t1 = message.getRoot<T1>();
printf("%d\n", t1.getI0());
}
int main(int argc, char **argv)
{
if (argc >= 2) {
readT1(STDIN_FILENO);
}
writeT1(STDOUT_FILENO);
return 0;
}