mirror of
https://github.com/zap-proto/lua.git
synced 2026-10-30 15:04:38 +00:00
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).
99 lines
1.9 KiB
Plaintext
99 lines
1.9 KiB
Plaintext
@0xa0d78d3689d48a0b;
|
|
|
|
using import "enums.zap".EnumType2;
|
|
using import "struct.zap".S1;
|
|
using Lua = import "lua.zap";
|
|
|
|
const pi :Float32 = 3.14159;
|
|
|
|
struct T1 {
|
|
struct T2 {
|
|
f0 @0 :Float32;
|
|
f1 @1 :Float64;
|
|
sd0 @2 :Data;
|
|
}
|
|
|
|
i0 @0 :UInt32;
|
|
i1 @1 :UInt16;
|
|
i2 @3 :Int8;
|
|
b0 @2 :Bool;
|
|
b1 @4 :Bool;
|
|
i3 @5 :Int32;
|
|
s0 @6 :T2;
|
|
e0 @7 :EnumType1;
|
|
l0 @8 :List(Int8);
|
|
t0 @9 :Text;
|
|
d0 @11 :Data;
|
|
e1 @10 :EnumType2;
|
|
|
|
enum EnumType1 $Lua.naming("lower_underscore") {
|
|
enum1 @0;
|
|
enum2 @1;
|
|
enum3 @2;
|
|
enum4 @3 $Lua.literal("wEirdENum4");
|
|
upperDash @4 $Lua.naming("upper_dash");
|
|
}
|
|
|
|
# unnamed union
|
|
union {
|
|
ui0 @12 :Int32;
|
|
ui1 @13 :Int32;
|
|
uv0 @14 :Void;
|
|
}
|
|
|
|
# group
|
|
g0 :group {
|
|
ui2 @15 :UInt32;
|
|
}
|
|
|
|
# named union = unamed union in a group
|
|
u0 :union {
|
|
ui3 @16 :UInt16;
|
|
uv1 @17 :Void;
|
|
ug0 :group {
|
|
ugv0 @18 :Void;
|
|
ugu0 @19 :UInt32;
|
|
}
|
|
ut0 @26 :Text;
|
|
}
|
|
|
|
ls0 @20 :List(T2);
|
|
|
|
du0 @21 :UInt32 = 65535;
|
|
db0 @22 :Bool = true;
|
|
end @23 :Bool; # "end" is lua's reserved word
|
|
o0 @24 :AnyPointer;
|
|
lt0 @25 :List(Text);
|
|
ld0 @27 :List(Data);
|
|
# u1: union {
|
|
# g1 :group {
|
|
# v1 @17 :Void;
|
|
# ui4 @18 :UInt32;
|
|
# }
|
|
# g2 :group {
|
|
# b2 @19 :Bool;
|
|
# }
|
|
# }
|
|
const welcomeText :Text = "Hello";
|
|
# Doesn't work for now
|
|
# const constT2 :T2 = (f0 = 12345.67, f1 = 9876.54, sd0 = "\0\1\2\3");
|
|
u64 @28 :UInt64;
|
|
}
|
|
|
|
struct T3 {
|
|
lsU16 @0 :List(UInt16);
|
|
lsU32 @1 :List(UInt32);
|
|
lsU64 @2 :List(UInt64);
|
|
lsI16 @3 :List(Int16);
|
|
lsI32 @4 :List(Int32);
|
|
lsI64 @5 :List(Int64);
|
|
}
|
|
|
|
struct T4 {
|
|
}
|
|
|
|
struct T5 {
|
|
llt0 @0 :List(List(Text));
|
|
lllt0 @1 :List(List(List(Text)));
|
|
}
|