util.table, Makefile: New C module that allows pre-allocation of tables to improve performance and decrease memory fragmentation
authorMatthew Wild <mwild1@gmail.com>
Tue, 31 Mar 2015 11:59:17 +0100
changeset 6613 7c4cf87f4dff
parent 6611 b6e558febb7a
child 6614 65dd3770bcb0
util.table, Makefile: New C module that allows pre-allocation of tables to improve performance and decrease memory fragmentation
util-src/Makefile
util-src/table.c
--- a/util-src/Makefile	Fri Mar 27 22:19:44 2015 +0000
+++ b/util-src/Makefile	Tue Mar 31 11:59:17 2015 +0100
@@ -14,9 +14,9 @@
 .PHONY: all install clean
 .SUFFIXES: .c .o .so
 
-all: encodings.so hashes.so net.so pposix.so signal.so
+all: encodings.so hashes.so net.so pposix.so signal.so table.so
 
-install: encodings.so hashes.so net.so pposix.so signal.so
+install: encodings.so hashes.so net.so pposix.so signal.so table.so
 	install *.so ../util/
 
 clean:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/util-src/table.c	Tue Mar 31 11:59:17 2015 +0100
@@ -0,0 +1,14 @@
+#include <lua.h>
+#include <lauxlib.h>
+
+static int Lcreate_table(lua_State* L) {
+	lua_createtable(L, luaL_checkinteger(L, 1), luaL_checkinteger(L, 2));
+	return 1;
+}
+
+int luaopen_util_table(lua_State *L) {
+	lua_newtable(L);
+	lua_pushcfunction(L, Lcreate_table);
+	lua_setfield(L, -2, "create");
+	return 1;
+}