From fd33b69d78dc596280a86e762e60cba019db401d Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 29 Jan 2010 20:45:32 +0000 Subject: [PATCH] moved built-in Lua to ag.lua, converting to C with xxd git-svn-id: svn://anubis/anaglym/trunk@232 99a6e188-d820-4881-8870-2d33a10e2619 --- Makefile | 6 +++++- ag.cc | 53 +++-------------------------------------------------- ag.lua | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ag_lua.h | 8 ++++++++ 4 files changed, 68 insertions(+), 51 deletions(-) create mode 100644 ag.lua create mode 100644 ag_lua.h diff --git a/Makefile b/Makefile index d772175..27d33ad 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,8 @@ WINDOWS := 1 endif TARGET := anaglym -COBJS := $(patsubst %.c,%.o,$(wildcard *.c)) +SOURCES := $(wildcard *.c) ag_lua.c +COBJS := $(patsubst %.c,%.o,$(SOURCES)) CXXOBJS := $(subst sdl_keymap.o,,$(patsubst %.cc,%.o,$(wildcard *.cc))) sdl_keymap.o OBJS := $(COBJS) $(CXXOBJS) CDEPS := $(COBJS:.o=.dep) @@ -57,6 +58,9 @@ all: $(TARGET) $(TARGET): $(OBJS) wfobj/WFObj.o OdeWorld/OdeWorld.o TextureCache/TextureCache.o $(CXX) -o $@ $^ $(LDFLAGS) +ag_lua.c: ag.lua + xxd -i $< > $@ + .PHONY: wfobj/WFObj.o wfobj/WFObj.o: $(MAKE) -C wfobj diff --git a/ag.cc b/ag.cc index 3da211c..7aa7e33 100644 --- a/ag.cc +++ b/ag.cc @@ -1,5 +1,6 @@ #include "ag.h" +#include "ag_lua.h" #include "anaglym.h" #include "Engine.h" #include "Video.h" @@ -76,57 +77,9 @@ namespace ag }; luaL_register(L, "ag", functions); - luaL_loadstring(L, - "next = ag.next\n" + ag_lua[ag_lua_len - 1] = '\0'; + luaL_loadstring(L, (const char *) ag_lua); - "type = ag.type\n" - - "pairs = function(table)\n" - " return next, table, nil\n" - "end\n" - - "ipairs = function(table)\n" - " local iter_func = function(t, i)\n" - " i = i + 1\n" - " if t[i] == nil then\n" - " return nil\n" - " else\n" - " return i, t[i]\n" - " end\n" - " end\n" - " return iter_func, table, 0\n" - "end\n" - - "ag.createAMotor = function(obj1, obj2, axis0, axis1, axis2)\n" - " local o1 = obj1\n" - " local o2 = obj2\n" - " local num_axes = 1\n" - " if (type(obj1) == \"number\") then\n" - " if (obj1 == 0) then\n" - " o1 = { id = 0 }\n" - " end\n" - " end\n" - " if (type(obj2) == \"number\") then\n" - " if (obj2 == 0) then\n" - " o2 = { id = 0 }\n" - " end\n" - " end\n" - " local num_axes = 0\n" - " if (axis0 ~= nil) then\n" - " setAMotorAxis(0, axis0)\n" - " num_axes = 1\n" - " if (axis1 ~= nil) then\n" - " setAMotorAxis(1, axis1)\n" - " num_axes = 1\n" - " if (axis2 ~= nil) then\n" - " setAMotorAxis(2, axis2)\n" - " num_axes = 2\n" - " end\n" - " end\n" - " end\n" - " ag.setAMotorNumAxes(num_axes)\n" - "end\n" - ); lua_pcall(L, 0, 0, 0); } diff --git a/ag.lua b/ag.lua new file mode 100644 index 0000000..e1308d2 --- /dev/null +++ b/ag.lua @@ -0,0 +1,52 @@ +next = ag.next + +type = ag.type + +pairs = function(table) + return next, table, nil +end + +ipairs = function(table) + local iter_func = function(t, i) + i = i + 1 + if t[i] == nil then + return nil + else + return i, t[i] + end + end + return iter_func, table, 0 +end + +ag.createAMotor = function(obj1, obj2, axis0, axis1, axis2) + local function setAMotorAxis(amotor, anum, axis) + end + local o1 = obj1 + local o2 = obj2 + local num_axes = 1 + if (type(obj1) == "number") then + if (obj1 == 0) then + o1 = { id = 0 } + end + end + if (type(obj2) == "number") then + if (obj2 == 0) then + o2 = { id = 0 } + end + end + local num_axes = 0 + if (axis0 ~= nil) then + setAMotorAxis(0, axis0) + num_axes = 1 + if (axis1 ~= nil) then + setAMotorAxis(1, axis1) + num_axes = 1 + if (axis2 ~= nil) then + setAMotorAxis(2, axis2) + num_axes = 2 + end + end + end + ag.setAMotorNumAxes(num_axes) +end + diff --git a/ag_lua.h b/ag_lua.h new file mode 100644 index 0000000..b6fcb9f --- /dev/null +++ b/ag_lua.h @@ -0,0 +1,8 @@ + +#ifndef AG_LUA_H +#define AG_LUA_H + +extern unsigned char ag_lua[]; +extern unsigned int ag_lua_len; + +#endif