summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2011-12-09 12:06:22 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-12-09 12:06:22 (GMT)
commitf5a58d14f2df42f5c8710df3f42d611c4c456c1b (patch)
tree915fe1a141e4458ae8c60264a36beacc427d5e15 /src
parent056e811d2f1f61524cc31865850350a00d1f338a (diff)
downloadpowder-f5a58d14f2df42f5c8710df3f42d611c4c456c1b.zip
powder-f5a58d14f2df42f5c8710df3f42d611c4c456c1b.tar.gz
Use static table for parts array, Uses a tonne of memory but improves performance a lot.
Diffstat (limited to 'src')
-rw-r--r--src/luaconsole.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/luaconsole.c b/src/luaconsole.c
index d0430ef..a80ba2f 100644
--- a/src/luaconsole.c
+++ b/src/luaconsole.c
@@ -101,7 +101,7 @@ void luacon_open(){
lua_setfield(l, tptPropertiesVersion, "build");
lua_setfield(l, tptProperties, "version");
- lua_newtable(l);
+ /*lua_newtable(l);
tptParts = lua_gettop(l);
lua_newtable(l);
tptPartsMeta = lua_gettop(l);
@@ -110,6 +110,26 @@ void luacon_open(){
lua_pushcfunction(l, luacon_partsread);
lua_setfield(l, tptPartsMeta, "__index");
lua_setmetatable(l, tptParts);
+ lua_setfield(l, tptProperties, "parts");*/
+ lua_newtable(l);
+ tptParts = lua_gettop(l);
+ for(i = 0; i < NPART; i++)
+ {
+ int currentPart, currentPartMeta;
+ lua_newtable(l);
+ currentPart = lua_gettop(l);
+ lua_newtable(l);
+ currentPartMeta = lua_gettop(l);
+ lua_pushinteger(l, i);
+ lua_setfield(l, currentPart, "id");
+ lua_pushcfunction(l, luacon_partwrite);
+ lua_setfield(l, currentPartMeta, "__newindex");
+ lua_pushcfunction(l, luacon_partread);
+ lua_setfield(l, currentPartMeta, "__index");
+ lua_setmetatable(l, currentPart);
+
+ lua_rawseti (l, tptParts, i);
+ }
lua_setfield(l, tptProperties, "parts");
lua_newtable(l);