Skip to content

Commit aa686e3

Browse files
committed
initial commit: basic library framework
This first commit includes the LICENSE and the .gitignore in addition to the beginnings of the zlua (name tbd) library. At this stage src/zlua.zig contains a very basic wrapper around the Lua C API. The goal is to expose every function in a Zig fashion. The build.zig script contains a single entry point `zig build test` to run tests. The intended use of this library will be to include in other projects and link as a package/library.
0 parents  commit aa686e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+30331
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
zig-cache/

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Nathan Craddock
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

build.zig

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.build.Builder) void {
4+
const mode = b.standardReleaseOptions();
5+
6+
const tests = b.addTest("src/zlua.zig");
7+
link(b, tests);
8+
tests.setBuildMode(mode);
9+
10+
const test_step = b.step("test", "Run zlua library tests");
11+
test_step.dependOn(&tests.step);
12+
}
13+
14+
fn dir() []const u8 {
15+
return std.fs.path.dirname(@src().file) orelse ".";
16+
}
17+
18+
pub fn link(b: *std.build.Builder, step: *std.build.LibExeObjStep) void {
19+
const lib = buildLua(b, step);
20+
step.linkLibrary(lib);
21+
step.linkLibC();
22+
}
23+
24+
const lib_dir = "lib/lua-5.4.4/src/";
25+
26+
fn buildLua(b: *std.build.Builder, step: *std.build.LibExeObjStep) *std.build.LibExeObjStep {
27+
const lib_path = std.fs.path.join(b.allocator, &.{ dir(), "src/zlua.zig" }) catch unreachable;
28+
const lib = b.addStaticLibrary("lua", lib_path);
29+
lib.setBuildMode(step.build_mode);
30+
lib.setTarget(step.target);
31+
32+
step.addIncludeDir(std.fs.path.join(b.allocator, &.{ dir(), lib_dir }) catch unreachable);
33+
34+
const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, lib.target) catch unreachable).target;
35+
const flags = switch (target.os.tag) {
36+
.linux => [_][]const u8{
37+
"-std=gnu99",
38+
"-DLUA_USE_LINUX",
39+
},
40+
.macos => [_][]const u8{
41+
"-std=gnu99",
42+
"-DLUA_USE_MACOSX",
43+
},
44+
.windows => [_][]const u8{
45+
"-std=gnu99",
46+
"-DLUA_USE_WINDOWS",
47+
},
48+
else => [_][]const u8{
49+
"-std=gnu99",
50+
"-DLUA_USE_POSIX",
51+
},
52+
};
53+
54+
inline for (lua_source_files) |file| {
55+
const path = std.fs.path.join(b.allocator, &.{ dir(), lib_dir ++ file }) catch unreachable;
56+
step.addCSourceFile(path, &flags);
57+
}
58+
59+
return lib;
60+
}
61+
62+
const lua_source_files = [_][]const u8{
63+
"lapi.c",
64+
"lcode.c",
65+
"lctype.c",
66+
"ldebug.c",
67+
"ldo.c",
68+
"ldump.c",
69+
"lfunc.c",
70+
"lgc.c",
71+
"llex.c",
72+
"lmem.c",
73+
"lobject.c",
74+
"lopcodes.c",
75+
"lparser.c",
76+
"lstate.c",
77+
"lstring.c",
78+
"ltable.c",
79+
"ltm.c",
80+
"lundump.c",
81+
"lvm.c",
82+
"lzio.c",
83+
"lauxlib.c",
84+
"lbaselib.c",
85+
"lcorolib.c",
86+
"ldblib.c",
87+
"liolib.c",
88+
"lmathlib.c",
89+
"loadlib.c",
90+
"loslib.c",
91+
"lstrlib.c",
92+
"ltablib.c",
93+
"lutf8lib.c",
94+
"linit.c",
95+
};

lib/lua-5.4.4/LICENSE

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright © 1994–2021 Lua.org, PUC-Rio.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

lib/lua-5.4.4/Makefile

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Makefile for installing Lua
2+
# See doc/readme.html for installation and customization instructions.
3+
4+
# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================
5+
6+
# Your platform. See PLATS for possible values.
7+
PLAT= guess
8+
9+
# Where to install. The installation starts in the src and doc directories,
10+
# so take care if INSTALL_TOP is not an absolute path. See the local target.
11+
# You may want to make INSTALL_LMOD and INSTALL_CMOD consistent with
12+
# LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h.
13+
INSTALL_TOP= /usr/local
14+
INSTALL_BIN= $(INSTALL_TOP)/bin
15+
INSTALL_INC= $(INSTALL_TOP)/include
16+
INSTALL_LIB= $(INSTALL_TOP)/lib
17+
INSTALL_MAN= $(INSTALL_TOP)/man/man1
18+
INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V
19+
INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V
20+
21+
# How to install. If your install program does not support "-p", then
22+
# you may have to run ranlib on the installed liblua.a.
23+
INSTALL= install -p
24+
INSTALL_EXEC= $(INSTALL) -m 0755
25+
INSTALL_DATA= $(INSTALL) -m 0644
26+
#
27+
# If you don't have "install" you can use "cp" instead.
28+
# INSTALL= cp -p
29+
# INSTALL_EXEC= $(INSTALL)
30+
# INSTALL_DATA= $(INSTALL)
31+
32+
# Other utilities.
33+
MKDIR= mkdir -p
34+
RM= rm -f
35+
36+
# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======
37+
38+
# Convenience platforms targets.
39+
PLATS= guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris
40+
41+
# What to install.
42+
TO_BIN= lua luac
43+
TO_INC= lua.h luaconf.h lualib.h lauxlib.h lua.hpp
44+
TO_LIB= liblua.a
45+
TO_MAN= lua.1 luac.1
46+
47+
# Lua version and release.
48+
V= 5.4
49+
R= $V.4
50+
51+
# Targets start here.
52+
all: $(PLAT)
53+
54+
$(PLATS) help test clean:
55+
@cd src && $(MAKE) $@
56+
57+
install: dummy
58+
cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)
59+
cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN)
60+
cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)
61+
cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)
62+
cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)
63+
64+
uninstall:
65+
cd src && cd $(INSTALL_BIN) && $(RM) $(TO_BIN)
66+
cd src && cd $(INSTALL_INC) && $(RM) $(TO_INC)
67+
cd src && cd $(INSTALL_LIB) && $(RM) $(TO_LIB)
68+
cd doc && cd $(INSTALL_MAN) && $(RM) $(TO_MAN)
69+
70+
local:
71+
$(MAKE) install INSTALL_TOP=../install
72+
73+
# make may get confused with install/ if it does not support .PHONY.
74+
dummy:
75+
76+
# Echo config parameters.
77+
echo:
78+
@cd src && $(MAKE) -s echo
79+
@echo "PLAT= $(PLAT)"
80+
@echo "V= $V"
81+
@echo "R= $R"
82+
@echo "TO_BIN= $(TO_BIN)"
83+
@echo "TO_INC= $(TO_INC)"
84+
@echo "TO_LIB= $(TO_LIB)"
85+
@echo "TO_MAN= $(TO_MAN)"
86+
@echo "INSTALL_TOP= $(INSTALL_TOP)"
87+
@echo "INSTALL_BIN= $(INSTALL_BIN)"
88+
@echo "INSTALL_INC= $(INSTALL_INC)"
89+
@echo "INSTALL_LIB= $(INSTALL_LIB)"
90+
@echo "INSTALL_MAN= $(INSTALL_MAN)"
91+
@echo "INSTALL_LMOD= $(INSTALL_LMOD)"
92+
@echo "INSTALL_CMOD= $(INSTALL_CMOD)"
93+
@echo "INSTALL_EXEC= $(INSTALL_EXEC)"
94+
@echo "INSTALL_DATA= $(INSTALL_DATA)"
95+
96+
# Echo pkg-config data.
97+
pc:
98+
@echo "version=$R"
99+
@echo "prefix=$(INSTALL_TOP)"
100+
@echo "libdir=$(INSTALL_LIB)"
101+
@echo "includedir=$(INSTALL_INC)"
102+
103+
# Targets that do not create files (not all makes understand .PHONY).
104+
.PHONY: all $(PLATS) help test clean install uninstall local dummy echo pc
105+
106+
# (end of Makefile)

lib/lua-5.4.4/README

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
This is Lua 5.4.4, released on 13 Jan 2022.
3+
4+
For installation instructions, license details, and
5+
further information about Lua, see doc/readme.html.
6+

0 commit comments

Comments
 (0)