diff --git a/3rd/Makefile.am b/3rd/Makefile.am deleted file mode 100644 index bad5c4b..0000000 --- a/3rd/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -EXTRA_DIST = lua-5.3.4/*.c lua-5.3.4/*.h lua-5.3.4/Makefile - -all: - cd $(top_srcdir)/3rd/lua-5.3.4 && make linux - -clean-local: - cd $(top_srcdir)/3rd/lua-5.3.4 && make clean \ No newline at end of file diff --git a/3rd/jsmn/Makefile b/3rd/jsmn/Makefile deleted file mode 100755 index f89701f..0000000 --- a/3rd/jsmn/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -# You can put your build options here --include config.mk - -all: libjsmn.a - -libjsmn.a: jsmn.o - $(AR) rc $@ $^ - -%.o: %.c jsmn.h - $(CC) -c $(CFLAGS) $< -o $@ - -test: test_default test_strict test_links test_strict_links -test_default: test/tests.c - $(CC) $(CFLAGS) $(LDFLAGS) $< -o test/$@ - ./test/$@ -test_strict: test/tests.c - $(CC) -DJSMN_STRICT=1 $(CFLAGS) $(LDFLAGS) $< -o test/$@ - ./test/$@ -test_links: test/tests.c - $(CC) -DJSMN_PARENT_LINKS=1 $(CFLAGS) $(LDFLAGS) $< -o test/$@ - ./test/$@ -test_strict_links: test/tests.c - $(CC) -DJSMN_STRICT=1 -DJSMN_PARENT_LINKS=1 $(CFLAGS) $(LDFLAGS) $< -o test/$@ - ./test/$@ - -jsmn_test.o: jsmn_test.c libjsmn.a - -simple_example: example/simple.o libjsmn.a - $(CC) $(LDFLAGS) $^ -o $@ - -jsondump: example/jsondump.o libjsmn.a - $(CC) $(LDFLAGS) $^ -o $@ - -clean: - rm -f *.o example/*.o - rm -f *.a *.so - rm -f simple_example - rm -f jsondump - -.PHONY: all clean test - diff --git a/3rd/lua-5.3.4/Makefile b/3rd/lua-5.3.4/Makefile deleted file mode 100644 index 4935306..0000000 --- a/3rd/lua-5.3.4/Makefile +++ /dev/null @@ -1,204 +0,0 @@ -# Makefile for building Lua -# See ../doc/readme.html for installation and customization instructions. - -# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= - -# Your platform. See PLATS for possible values. -PLAT= none - -CC= gcc -std=gnu99 -CFLAGS= -O2 -g -Wall -Wextra -DLUA_COMPAT_5_2 -fPIC $(SYSCFLAGS) $(MYCFLAGS) -LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS) -LIBS= -lm $(SYSLIBS) $(MYLIBS) - -AR= ar rcu -RANLIB= ranlib -RM= rm -f - -SYSCFLAGS= -SYSLDFLAGS= -SYSLIBS= - -MYCFLAGS= -MYLDFLAGS= -MYLIBS= -MYOBJS= - -# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE ======= - -PLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris -LUA_SO = core.so -LUA_A= liblua.a -CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \ - lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \ - ltm.o lundump.o lvm.o lzio.o -LIB_O= lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \ - lmathlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o loadlib.o linit.o -BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS) - -LUA_T= lua -LUA_O= lua.o - -LUAC_T= luac -LUAC_O= luac.o - -ALL_O= $(BASE_O) $(LUA_O) $(LUAC_O) -ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) $(LUA_SO) -ALL_A= $(LUA_A) $(LUA_SO) - -# Targets start here. -default: $(PLAT) - -all: $(ALL_T) - -o: $(ALL_O) - -a: $(ALL_A) - -$(LUA_A): $(BASE_O) - $(AR) $@ $(BASE_O) - $(RANLIB) $@ - -$(LUA_SO): $(BASE_O) - gcc -shared $(BASE_O) -o $@ -ldl -lm - -$(LUA_T): $(LUA_O) $(LUA_A) - $(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS) - -$(LUAC_T): $(LUAC_O) $(LUA_A) - $(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS) - -clean: - $(RM) $(ALL_T) $(ALL_O) - -depend: - @$(CC) $(CFLAGS) -MM l*.c - -distdir: - -install: - -echo: - @echo "PLAT= $(PLAT)" - @echo "CC= $(CC)" - @echo "CFLAGS= $(CFLAGS)" - @echo "LDFLAGS= $(SYSLDFLAGS)" - @echo "LIBS= $(LIBS)" - @echo "AR= $(AR)" - @echo "RANLIB= $(RANLIB)" - @echo "RM= $(RM)" - -# Convenience targets for popular platforms -ALL= all - -none: - @echo "Please do 'make PLATFORM' where PLATFORM is one of these:" - @echo " $(PLATS)" - -aix: - $(MAKE) $(ALL) CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl" SYSLDFLAGS="-brtl -bexpall" - -bsd: - $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-Wl,-E" - -c89: - $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_C89" CC="gcc -std=c89" - @echo '' - @echo '*** C89 does not guarantee 64-bit integers for Lua.' - @echo '' - - -freebsd: - $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -lreadline" - -generic: $(ALL) - -linux: - $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline" - -macosx: - $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_MACOSX" SYSLIBS="-lreadline" CC=cc - -mingw: - $(MAKE) "LUA_A=lua53.dll" "LUA_T=lua.exe" \ - "AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \ - "SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe - $(MAKE) "LUAC_T=luac.exe" luac.exe - -posix: - $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX" - -solaris: - $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN -D_REENTRANT" SYSLIBS="-ldl" - -# list targets that do not create files (but not all makes understand .PHONY) -.PHONY: all $(PLATS) default o a clean depend echo none - -# DO NOT DELETE - -lapi.o: lapi.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ - lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lstring.h \ - ltable.h lundump.h lvm.h -lauxlib.o: lauxlib.c lprefix.h lua.h luaconf.h lauxlib.h -lbaselib.o: lbaselib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -lbitlib.o: lbitlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -lcode.o: lcode.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \ - llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \ - ldo.h lgc.h lstring.h ltable.h lvm.h -lcorolib.o: lcorolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -lctype.o: lctype.c lprefix.h lctype.h lua.h luaconf.h llimits.h -ldblib.o: ldblib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -ldebug.o: ldebug.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ - lobject.h ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h \ - ldebug.h ldo.h lfunc.h lstring.h lgc.h ltable.h lvm.h -ldo.o: ldo.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ - lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h \ - lparser.h lstring.h ltable.h lundump.h lvm.h -ldump.o: ldump.c lprefix.h lua.h luaconf.h lobject.h llimits.h lstate.h \ - ltm.h lzio.h lmem.h lundump.h -lfunc.o: lfunc.c lprefix.h lua.h luaconf.h lfunc.h lobject.h llimits.h \ - lgc.h lstate.h ltm.h lzio.h lmem.h -lgc.o: lgc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ - llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h -linit.o: linit.c lprefix.h lua.h luaconf.h lualib.h lauxlib.h -liolib.o: liolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -llex.o: llex.c lprefix.h lua.h luaconf.h lctype.h llimits.h ldebug.h \ - lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lgc.h llex.h lparser.h \ - lstring.h ltable.h -lmathlib.o: lmathlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -lmem.o: lmem.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ - llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h -loadlib.o: loadlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -lobject.o: lobject.c lprefix.h lua.h luaconf.h lctype.h llimits.h \ - ldebug.h lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h \ - lvm.h -lopcodes.o: lopcodes.c lprefix.h lopcodes.h llimits.h lua.h luaconf.h -loslib.o: loslib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -lparser.o: lparser.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \ - llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \ - ldo.h lfunc.h lstring.h lgc.h ltable.h -lstate.o: lstate.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ - lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h llex.h \ - lstring.h ltable.h -lstring.o: lstring.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \ - lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h -lstrlib.o: lstrlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -ltable.o: ltable.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ - llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h -ltablib.o: ltablib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -ltm.o: ltm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ - llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h ltable.h lvm.h -lua.o: lua.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -luac.o: luac.c lprefix.h lua.h luaconf.h lauxlib.h lobject.h llimits.h \ - lstate.h ltm.h lzio.h lmem.h lundump.h ldebug.h lopcodes.h -lundump.o: lundump.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \ - lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h \ - lundump.h -lutf8lib.o: lutf8lib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -lvm.o: lvm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ - llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h \ - ltable.h lvm.h -lzio.o: lzio.c lprefix.h lua.h luaconf.h llimits.h lmem.h lstate.h \ - lobject.h ltm.h lzio.h - -# (end of Makefile) diff --git a/APIs/api.lua b/APIs/api.lua index 4910092..f2e3caa 100644 --- a/APIs/api.lua +++ b/APIs/api.lua @@ -3,6 +3,8 @@ __ROOT__ = __api__.root -- set require path package.path = __ROOT__ .. '/?.lua;'..__api__.apiroot..'/?.lua' package.cpath = __api__.apiroot..'/?.so' + +require("antd") require("std") require("utils") require("extra_mime") diff --git a/APIs/sqlite.lua b/APIs/sqlite.lua index 319a538..7d2d38e 100644 --- a/APIs/sqlite.lua +++ b/APIs/sqlite.lua @@ -1,4 +1,4 @@ -sqlite = modules.sqlite() +sqlite = modules.sqlite() if sqlite == nil then return 0 end require("OOP") diff --git a/APIs/std.lua b/APIs/std.lua index ff95d15..b9efd94 100644 --- a/APIs/std.lua +++ b/APIs/std.lua @@ -1,6 +1,17 @@ std = modules.std() bytes = modules.bytes() array = modules.array() + +modules.sqlite = function() + if not sqlite then + sqlite = require("sqlitedb") + sqlite.getdb = function(s) + return sqlite._getdb(__api__.dbpath.."/"..s..".db") + end + end + return sqlite +end + RESPONSE_HEADER = { status = 200, header = {}, diff --git a/APIs/utils.lua b/APIs/utils.lua index 0d499b3..539a114 100644 --- a/APIs/utils.lua +++ b/APIs/utils.lua @@ -83,7 +83,7 @@ function utils.url_parser(uri) return obj end -JSON = modules.JSON() +JSON = require("json") function JSON.encode(obj) local t = type(obj) diff --git a/Makefile.am b/Makefile.am index 4b2c847..ea01326 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,22 +16,14 @@ AM_CPPFLAGS += -W -Wall -g -std=c99 -fPIC # main plugin lib_LTLIBRARIES = lua.la lua_la_LDFLAGS = -module -avoid-version -shared -lua_la_SOURCES = plugin-wrapper.c\ - 3rd/jsmn/jsmn.c \ - array-wrapper.c \ - json-wrapper.c \ - lua-api.c +lua_la_SOURCES = lua-api.c # lua libraris & modules -SUBDIRS = 3rd . lib +SUBDIRS = . lib -if DB - lua_la_SOURCES += db-wrapper.c -endif - -EXTRA_DIST = README.md 3rd/jsmn/jsmn.h APIs lua-api.h +EXTRA_DIST = README.md APIs install-data-local: mkdir -p $(prefix)/lib/lua cp -v APIs/* $(prefix)/lib/lua - cp -v 3rd/lua-5.3.4/core.so $(prefix)/lib/lua \ No newline at end of file + cp -v lib/core/lua-5.3.4/core.so $(prefix)/lib/lua \ No newline at end of file diff --git a/array-wrapper.c b/array-wrapper.c deleted file mode 100644 index 263c77f..0000000 --- a/array-wrapper.c +++ /dev/null @@ -1,191 +0,0 @@ -#include "lua-api.h" -// add a length field, and -void lua_new_byte_array(lua_State*L, int n) -{ - size_t nbytes = sizeof(byte_array_t) + (n-1)*sizeof(unsigned char); - byte_array_t *a = (byte_array_t *)lua_newuserdata(L, nbytes); - luaL_getmetatable(L, BYTEARRAY); - lua_setmetatable(L, -2); - a->size = n; -} -static int l_new_barray (lua_State *L) { - int n = luaL_checknumber(L, 1); - lua_new_byte_array(L,n); - return 1; /* new userdatum is already on the stack */ -} -byte_array_t *l_check_barray (lua_State *L,int idx) { - void *ud = luaL_checkudata(L, idx, BYTEARRAY); - luaL_argcheck(L, ud != NULL, idx, "`byte array' expected"); - return (byte_array_t *)ud; -} - -static unsigned char *get_bel(lua_State *L) { - byte_array_t *a = l_check_barray(L,1); - int index = luaL_checknumber(L, 2); - luaL_argcheck(L, 1 <= index && index <= a->size, 2, - "index out of range"); - - /* return element address */ - return &a->data[index - 1]; - } - -static int l_set_barray (lua_State *L) { - unsigned char value = luaL_checknumber(L, 3); - *get_bel(L) = value; - return 0; -} - -static int l_get_barray (lua_State *L) { - lua_pushnumber(L, *get_bel(L)); - return 1; -} - -static int l_get_barray_size (lua_State *L) { - byte_array_t *a = l_check_barray(L,1); - lua_pushnumber(L, a->size); - return 1; -} - -static int l_barray_to_string (lua_State *L) { - byte_array_t *a = l_check_barray(L,1); - char * d = (char*) malloc(a->size+1); - memcpy(d, a->data, a->size); - d[a->size] = '\0'; - lua_pushstring(L, d); - if(d) - free(d); - return 1; -} - -static int l_barray_write(lua_State* L) -{ - byte_array_t *a = l_check_barray(L,1); - const char* f = luaL_checkstring(L,2); - FILE *fp; - fp = fopen(f,"wb"); - - if(!fp) - lua_pushboolean(L,0); - else - { - fwrite(a->data ,1, a->size ,fp); - lua_pushboolean(L,1); - fclose(fp); - } - return 1; -} - -static const struct luaL_Reg barraylib[] = { - {"new", l_new_barray}, - {"set", l_set_barray}, - {"get", l_get_barray}, - {"size",l_get_barray_size}, - {"__tostring", l_barray_to_string}, - {"write", l_barray_write}, - {NULL, NULL} -}; - - - -// ARRAY -void lua_new_array(lua_State*L, int n) -{ - size_t nbytes = sizeof(array_t) + (n-1)*sizeof(double); - array_t *a = (array_t *)lua_newuserdata(L, nbytes); - luaL_getmetatable(L, ARRAY); - lua_setmetatable(L, -2); - a->size = n; -} -static int l_new_array (lua_State *L) { - int n = luaL_checknumber(L, 1); - lua_new_array(L,n); - return 1; /* new userdatum is already on the stack */ -} - -array_t *l_check_array (lua_State *L, int idx) { - void *ud = luaL_checkudata(L, idx, ARRAY); - luaL_argcheck(L, ud != NULL, idx, "`array' expected"); - return (array_t *)ud; -} - -static double *get_el(lua_State *L) { - array_t *a = l_check_array(L,1); - int index = luaL_checknumber(L, 2); - luaL_argcheck(L, 1 <= index && index <= a->size, 2, - "index out of range"); - - /* return element address */ - return &a->data[index - 1]; - } - -static int l_set_array (lua_State *L) { - double value = luaL_checknumber(L, 3); - *get_el(L) = value; - return 0; -} - -static int l_get_array (lua_State *L) { - lua_pushnumber(L, *get_el(L)); - return 1; -} - -static int l_get_array_size (lua_State *L) { - array_t *a = l_check_array(L,1); - lua_pushnumber(L, a->size); - return 1; -} -static int l_array_to_string (lua_State *L) { - array_t *a = l_check_array(L,1); - lua_pushfstring(L, "number array(%d)", a->size); - return 1; -} - -static const struct luaL_Reg arraylib [] = { - {"new", l_new_array}, - {"set", l_set_array}, - {"get", l_get_array}, - {"size",l_get_array_size}, - {"__tostring", l_array_to_string}, - {NULL, NULL} -}; -int luaopen_array (lua_State *L) { - luaL_newmetatable(L, ARRAY); - luaL_newlib(L, arraylib); - lua_pushstring(L, "__index"); - lua_pushstring(L, "get"); - lua_gettable(L, 2); /* get array.get */ - lua_settable(L, 1); /* metatable.__index = array.get */ - - lua_pushstring(L, "__newindex"); - lua_pushstring(L, "set"); - lua_gettable(L, 2); /* get array.set */ - lua_settable(L, 1); /* metatable.__newindex = array.set */ - - //lua_pushstring(L, "__index"); - //lua_pushvalue(L, -2); /* pushes the metatable */ - //lua_settable(L, -3); /* metatable.__index = metatable */ - // luaL_setfuncs(L, arraylib_m, 0); - // luaL_openlib(L, NULL, arraylib_m, 0); - // luaL_newlib(L, arraylib_f); - return 1; - } -int luaopen_barray (lua_State *L) { - luaL_newmetatable(L, BYTEARRAY); - luaL_newlib(L, barraylib); - lua_pushstring(L, "__index"); - lua_pushstring(L, "get"); - lua_gettable(L, 2); /* get array.get */ - lua_settable(L, 1); /* metatable.__index = array.get */ - - lua_pushstring(L, "__newindex"); - lua_pushstring(L, "set"); - lua_gettable(L, 2); /* get array.set */ - lua_settable(L, 1); - //lua_pushstring(L, "__index"); - //lua_pushvalue(L, -2); /* pushes the metatable */ - //lua_settable(L, -3); /* metatable.__index = metatable */ - //luaL_setfuncs(L, barraylib_m, 0); - //luaL_openlib(L, NULL, barraylib_m, 0); - //luaL_newlib(L, barraylib_f); - return 1; -} \ No newline at end of file diff --git a/configure.ac b/configure.ac index 7bde3b9..9d82c80 100644 --- a/configure.ac +++ b/configure.ac @@ -124,18 +124,12 @@ AM_CONDITIONAL([HAS_FFI], [test "$use_ffi" = "yes"]) AM_CONDITIONAL([HAS_CMAKE], [test "$has_cmake" = "yes"]) # find all config files AC_CONFIG_FILES([ - 3rd/Makefile Makefile lib/Makefile - lib/ulib/Makefile - lib/wurl/Makefile - lib/stmr/Makefile + lib/core/Makefile + lib/asl/Makefile ]) -if test "$use_ffi" = "yes"; then - AC_CONFIG_FILES([lib/ffi/Makefile]) -fi - if test x"${has_cmake}" == x"yes" ; then AC_CONFIG_FILES([lib/ann/Makefile lib/ann/fann/Makefile]) fi diff --git a/dist/lua-0.5.2b.tar.gz b/dist/lua-0.5.2b.tar.gz index e75ce21..daafac8 100644 Binary files a/dist/lua-0.5.2b.tar.gz and b/dist/lua-0.5.2b.tar.gz differ diff --git a/lib/Makefile.am b/lib/Makefile.am index 24f1970..1785a02 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,7 +1,4 @@ -SUBDIRS = ulib wurl stmr -if HAS_FFI - SUBDIRS += ffi -endif +SUBDIRS = core asl if HAS_CMAKE SUBDIRS += ann endif diff --git a/lib/ann/Makefile b/lib/ann/Makefile index 7cfd7a5..db3b7fe 100644 --- a/lib/ann/Makefile +++ b/lib/ann/Makefile @@ -240,14 +240,14 @@ am__relativize = \ dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ done; \ reldir="$$dir2" -ACLOCAL = ${SHELL} /src/cwp/ant-plugins/antd-lua-plugin/missing aclocal-1.15 +ACLOCAL = ${SHELL} /home/mrsang/build/antd-lua-plugin/missing aclocal-1.15 AMTAR = $${TAR-tar} AM_DEFAULT_VERBOSITY = 1 AR = ar -AUTOCONF = ${SHELL} /src/cwp/ant-plugins/antd-lua-plugin/missing autoconf -AUTOHEADER = ${SHELL} /src/cwp/ant-plugins/antd-lua-plugin/missing autoheader -AUTOMAKE = ${SHELL} /src/cwp/ant-plugins/antd-lua-plugin/missing automake-1.15 -AWK = mawk +AUTOCONF = ${SHELL} /home/mrsang/build/antd-lua-plugin/missing autoconf +AUTOHEADER = ${SHELL} /home/mrsang/build/antd-lua-plugin/missing autoheader +AUTOMAKE = ${SHELL} /home/mrsang/build/antd-lua-plugin/missing automake-1.15 +AWK = gawk CC = gcc CCDEPMODE = depmode=gcc3 CFLAGS = -g -O2 @@ -280,7 +280,7 @@ LIPO = LN_S = ln -s LTLIBOBJS = LT_SYS_LIBRARY_PATH = -MAKEINFO = ${SHELL} /src/cwp/ant-plugins/antd-lua-plugin/missing makeinfo +MAKEINFO = ${SHELL} /home/mrsang/build/antd-lua-plugin/missing makeinfo MANIFEST_TOOL = : MKDIR_P = /bin/mkdir -p NM = /usr/bin/nm -B @@ -300,13 +300,13 @@ PATH_SEPARATOR = : RANLIB = ranlib SED = /bin/sed SET_MAKE = -SHELL = /bin/sh +SHELL = /bin/bash STRIP = strip VERSION = 0.5.2b -abs_builddir = /src/cwp/ant-plugins/antd-lua-plugin/lib/ann -abs_srcdir = /src/cwp/ant-plugins/antd-lua-plugin/lib/ann -abs_top_builddir = /src/cwp/ant-plugins/antd-lua-plugin -abs_top_srcdir = /src/cwp/ant-plugins/antd-lua-plugin +abs_builddir = /home/mrsang/build/antd-lua-plugin/lib/ann +abs_srcdir = /home/mrsang/build/antd-lua-plugin/lib/ann +abs_top_builddir = /home/mrsang/build/antd-lua-plugin +abs_top_srcdir = /home/mrsang/build/antd-lua-plugin ac_ct_AR = ar ac_ct_CC = gcc ac_ct_DUMPBIN = @@ -336,7 +336,7 @@ host_vendor = pc htmldir = ${docdir} includedir = ${prefix}/include infodir = ${datarootdir}/info -install_sh = ${SHELL} /src/cwp/ant-plugins/antd-lua-plugin/install-sh +install_sh = ${SHELL} /home/mrsang/build/antd-lua-plugin/install-sh libdir = $(prefix)/lib/lua/ libexecdir = ${exec_prefix}/libexec localedir = ${datarootdir}/locale @@ -345,7 +345,7 @@ mandir = ${datarootdir}/man mkdir_p = $(MKDIR_P) oldincludedir = /usr/include pdfdir = ${docdir} -prefix = /src/www +prefix = /opt/www program_transform_name = s,x,x, psdir = ${docdir} runstatedir = ${localstatedir}/run diff --git a/lib/ann/lfann.h b/lib/ann/lfann.h index 58ffcfe..3a49e46 100644 --- a/lib/ann/lfann.h +++ b/lib/ann/lfann.h @@ -26,7 +26,7 @@ #include #include "../lualib.h" -#include "../../lua-api.h" +//#include "../../lua-api.h" #define LIB_NAME "ann" diff --git a/3rd/jsmn/LICENSE b/lib/asl/3rd/jsmn/LICENSE similarity index 100% rename from 3rd/jsmn/LICENSE rename to lib/asl/3rd/jsmn/LICENSE diff --git a/3rd/jsmn/README.md b/lib/asl/3rd/jsmn/README.md similarity index 100% rename from 3rd/jsmn/README.md rename to lib/asl/3rd/jsmn/README.md diff --git a/3rd/jsmn/example/jsondump.c b/lib/asl/3rd/jsmn/example/jsondump.c similarity index 100% rename from 3rd/jsmn/example/jsondump.c rename to lib/asl/3rd/jsmn/example/jsondump.c diff --git a/3rd/jsmn/example/simple.c b/lib/asl/3rd/jsmn/example/simple.c similarity index 100% rename from 3rd/jsmn/example/simple.c rename to lib/asl/3rd/jsmn/example/simple.c diff --git a/3rd/jsmn/jsmn.c b/lib/asl/3rd/jsmn/jsmn.c similarity index 100% rename from 3rd/jsmn/jsmn.c rename to lib/asl/3rd/jsmn/jsmn.c diff --git a/3rd/jsmn/jsmn.h b/lib/asl/3rd/jsmn/jsmn.h similarity index 100% rename from 3rd/jsmn/jsmn.h rename to lib/asl/3rd/jsmn/jsmn.h diff --git a/3rd/jsmn/library.json b/lib/asl/3rd/jsmn/library.json similarity index 100% rename from 3rd/jsmn/library.json rename to lib/asl/3rd/jsmn/library.json diff --git a/3rd/jsmn/test/test.h b/lib/asl/3rd/jsmn/test/test.h similarity index 100% rename from 3rd/jsmn/test/test.h rename to lib/asl/3rd/jsmn/test/test.h diff --git a/3rd/jsmn/test/tests.c b/lib/asl/3rd/jsmn/test/tests.c similarity index 100% rename from 3rd/jsmn/test/tests.c rename to lib/asl/3rd/jsmn/test/tests.c diff --git a/3rd/jsmn/test/testutil.h b/lib/asl/3rd/jsmn/test/testutil.h similarity index 100% rename from 3rd/jsmn/test/testutil.h rename to lib/asl/3rd/jsmn/test/testutil.h diff --git a/lib/ulib/3rd/zip/main.c b/lib/asl/3rd/zip/main.c similarity index 100% rename from lib/ulib/3rd/zip/main.c rename to lib/asl/3rd/zip/main.c diff --git a/lib/ulib/3rd/zip/miniz.c b/lib/asl/3rd/zip/miniz.c similarity index 100% rename from lib/ulib/3rd/zip/miniz.c rename to lib/asl/3rd/zip/miniz.c diff --git a/lib/ulib/3rd/zip/zip.c b/lib/asl/3rd/zip/zip.c similarity index 100% rename from lib/ulib/3rd/zip/zip.c rename to lib/asl/3rd/zip/zip.c diff --git a/lib/ulib/3rd/zip/zip.h b/lib/asl/3rd/zip/zip.h similarity index 100% rename from lib/ulib/3rd/zip/zip.h rename to lib/asl/3rd/zip/zip.h diff --git a/lib/asl/Makefile.am b/lib/asl/Makefile.am new file mode 100644 index 0000000..f04eb6a --- /dev/null +++ b/lib/asl/Makefile.am @@ -0,0 +1,38 @@ +lib_LTLIBRARIES = ulib.la +ulib_la_LDFLAGS = -module -avoid-version -shared +ulib_la_SOURCES = 3rd/zip/zip.c ulib.c + +lib_LTLIBRARIES += antd.la +antd_la_LDFLAGS = -module -avoid-version -shared +antd_la_SOURCES = antd.c + +lib_LTLIBRARIES += stmr.la +stmr_la_LDFLAGS = -module -avoid-version -shared +stmr_la_SOURCES = stmr.c + +lib_LTLIBRARIES += json.la +json_la_LDFLAGS = -module -avoid-version -shared +json_la_SOURCES = 3rd/jsmn/jsmn.c json.c + + +lib_LTLIBRARIES += wurl.la +wurl_la_LDFLAGS = -module -avoid-version -shared +wurl_la_SOURCES = wurl.c + +if HAS_FFI +lib_LTLIBRARIES += ffi.la +ffi_la_LDFLAGS = -module -avoid-version -shared -lffi +ffi_la_SOURCES = ffi.c +endif + +if DB +lib_LTLIBRARIES += sqlitedb.la +sqlitedb_la_LDFLAGS = -module -avoid-version -shared +sqlitedb_la_SOURCES = sqlitedb.c +endif + + + +libdir=$(prefix)/lib/lua/ + +EXTRA_DIST = 3rd/zip/miniz.c 3rd/zip/zip.h 3rd/jsmn/jsmn.h \ No newline at end of file diff --git a/plugin-wrapper.c b/lib/asl/antd.c similarity index 68% rename from plugin-wrapper.c rename to lib/asl/antd.c index 63058ea..5b51051 100644 --- a/plugin-wrapper.c +++ b/lib/asl/antd.c @@ -1,75 +1,196 @@ #include -#include "lua-api.h" - -//void header(int,const char*); -/* -static int l_header (lua_State *L) { - //int client = (int)luaL_checknumber(L, 1); - void* client = lua_touserdata (L, 1); - const char* s = luaL_checkstring(L,2); - ctype(client,s); - return 0; +#include "../lualib.h" +// add a length field, and +void lua_new_byte_array(lua_State*L, int n) +{ + size_t nbytes = sizeof(byte_array_t) + (n-1)*sizeof(unsigned char); + byte_array_t *a = (byte_array_t *)lua_newuserdata(L, nbytes); + luaL_getmetatable(L, BYTEARRAY); + lua_setmetatable(L, -2); + a->size = n; } -*/ - -//void redirect(int,const char*); -/* -static int l_redirect (lua_State *L) { - void* client = lua_touserdata (L, 1); - const char* s = luaL_checkstring(L,2); - redirect(client,s); - return 0; -}*/ - -/* -static int l_html (lua_State *L) { - void* client = lua_touserdata (L, 1); - html(client); - return 0; +static int l_new_barray (lua_State *L) { + int n = luaL_checknumber(L, 1); + lua_new_byte_array(L,n); + return 1; /* new userdatum is already on the stack */ } -*/ - -//void text(int); -/* -static int l_text (lua_State *L) { - void* client = lua_touserdata (L, 1); - text(client); - return 0; +byte_array_t *l_check_barray (lua_State *L,int idx) { + void *ud = luaL_checkudata(L, idx, BYTEARRAY); + luaL_argcheck(L, ud != NULL, idx, "`byte array' expected"); + return (byte_array_t *)ud; } -*/ -//void json(int); -/* -static int l_json (lua_State *L) { - void* client = lua_touserdata (L, 1); - json(client); - return 0; -}*/ +static unsigned char *get_bel(lua_State *L) { + byte_array_t *a = l_check_barray(L,1); + int index = luaL_checknumber(L, 2); + luaL_argcheck(L, 1 <= index && index <= a->size, 2, + "index out of range"); + + /* return element address */ + return &a->data[index - 1]; + } + +static int l_set_barray (lua_State *L) { + unsigned char value = luaL_checknumber(L, 3); + *get_bel(L) = value; + return 0; +} -//void jpeg(int); -/* -static int l_jpeg (lua_State *L) { - void* client = lua_touserdata (L, 1); - jpeg(client); - return 0; -}*/ +static int l_get_barray (lua_State *L) { + lua_pushnumber(L, *get_bel(L)); + return 1; +} + +static int l_get_barray_size (lua_State *L) { + byte_array_t *a = l_check_barray(L,1); + lua_pushnumber(L, a->size); + return 1; +} + +static int l_barray_to_string (lua_State *L) { + byte_array_t *a = l_check_barray(L,1); + char * d = (char*) malloc(a->size+1); + memcpy(d, a->data, a->size); + d[a->size] = '\0'; + lua_pushstring(L, d); + if(d) + free(d); + return 1; +} + +static int l_barray_write(lua_State* L) +{ + byte_array_t *a = l_check_barray(L,1); + const char* f = luaL_checkstring(L,2); + FILE *fp; + fp = fopen(f,"wb"); + + if(!fp) + lua_pushboolean(L,0); + else + { + fwrite(a->data ,1, a->size ,fp); + lua_pushboolean(L,1); + fclose(fp); + } + return 1; +} + +static const struct luaL_Reg barraylib[] = { + {"new", l_new_barray}, + {"set", l_set_barray}, + {"get", l_get_barray}, + {"size",l_get_barray_size}, + {"__tostring", l_barray_to_string}, + {"write", l_barray_write}, + {NULL, NULL} +}; + +int luaopen_bytes (lua_State *L) { + luaL_newmetatable(L, BYTEARRAY); + luaL_newlib(L, barraylib); + lua_pushstring(L, "__index"); + lua_pushstring(L, "get"); + lua_gettable(L, 2); /* get array.get */ + lua_settable(L, 1); /* metatable.__index = array.get */ + + lua_pushstring(L, "__newindex"); + lua_pushstring(L, "set"); + lua_gettable(L, 2); /* get array.set */ + lua_settable(L, 1); + //lua_pushstring(L, "__index"); + //lua_pushvalue(L, -2); /* pushes the metatable */ + //lua_settable(L, -3); /* metatable.__index = metatable */ + //luaL_setfuncs(L, barraylib_m, 0); + //luaL_openlib(L, NULL, barraylib_m, 0); + //luaL_newlib(L, barraylib_f); + return 1; +} + +// ARRAY +void lua_new_array(lua_State*L, int n) +{ + size_t nbytes = sizeof(array_t) + (n-1)*sizeof(double); + array_t *a = (array_t *)lua_newuserdata(L, nbytes); + luaL_getmetatable(L, ARRAY); + lua_setmetatable(L, -2); + a->size = n; +} +static int l_new_array (lua_State *L) { + int n = luaL_checknumber(L, 1); + lua_new_array(L,n); + return 1; /* new userdatum is already on the stack */ +} + +array_t *l_check_array (lua_State *L, int idx) { + void *ud = luaL_checkudata(L, idx, ARRAY); + luaL_argcheck(L, ud != NULL, idx, "`array' expected"); + return (array_t *)ud; +} + +static double *get_el(lua_State *L) { + array_t *a = l_check_array(L,1); + int index = luaL_checknumber(L, 2); + luaL_argcheck(L, 1 <= index && index <= a->size, 2, + "index out of range"); + + /* return element address */ + return &a->data[index - 1]; + } + +static int l_set_array (lua_State *L) { + double value = luaL_checknumber(L, 3); + *get_el(L) = value; + return 0; +} + +static int l_get_array (lua_State *L) { + lua_pushnumber(L, *get_el(L)); + return 1; +} + +static int l_get_array_size (lua_State *L) { + array_t *a = l_check_array(L,1); + lua_pushnumber(L, a->size); + return 1; +} +static int l_array_to_string (lua_State *L) { + array_t *a = l_check_array(L,1); + lua_pushfstring(L, "number array(%d)", a->size); + return 1; +} + +static const struct luaL_Reg arraylib [] = { + {"new", l_new_array}, + {"set", l_set_array}, + {"get", l_get_array}, + {"size",l_get_array_size}, + {"__tostring", l_array_to_string}, + {NULL, NULL} +}; +int luaopen_array (lua_State *L) { + luaL_newmetatable(L, ARRAY); + luaL_newlib(L, arraylib); + lua_pushstring(L, "__index"); + lua_pushstring(L, "get"); + lua_gettable(L, 2); /* get array.get */ + lua_settable(L, 1); /* metatable.__index = array.get */ + + lua_pushstring(L, "__newindex"); + lua_pushstring(L, "set"); + lua_gettable(L, 2); /* get array.set */ + lua_settable(L, 1); /* metatable.__newindex = array.set */ + + //lua_pushstring(L, "__index"); + //lua_pushvalue(L, -2); /* pushes the metatable */ + //lua_settable(L, -3); /* metatable.__index = metatable */ + // luaL_setfuncs(L, arraylib_m, 0); + // luaL_openlib(L, NULL, arraylib_m, 0); + // luaL_newlib(L, arraylib_f); + return 1; + } -//void octstream(int, char*); -/* -static int l_octstream (lua_State *L) { - void* client = lua_touserdata (L, 1); - const char* s = luaL_checkstring(L,2); - octstream(client,(char*)s); - return 0; -}*/ -//void textstream(int); -/* -static int l_textstream (lua_State *L) { - void* client = lua_touserdata (L, 1); - textstream(client); - return 0; -}*/ // int mime static int l_mime(lua_State* L) { @@ -146,11 +267,12 @@ static int l_upload (lua_State *L) { } //char* route(const char*); +/* static int l_route (lua_State *L) { const char* s = luaL_checkstring(L, 1); lua_pushstring(L, route(s)); return 1; -} +}*/ //char* htdocs(const char*); //#ifdef USE_DB @@ -565,7 +687,7 @@ static const struct luaL_Reg standard [] = { {"_b", l_b} , {"trim", l_trim}, {"upload", l_upload} , - {"route", l_route} , + //{"route", l_route} , {"mime", l_mime} , //{"is_bin", l_is_bin} , //{"_unknow", l_unknow} , @@ -586,8 +708,26 @@ static const struct luaL_Reg standard [] = { {NULL,NULL} }; -int luaopen_standard(lua_State *L) + + +int luaopen_std(lua_State *L) { luaL_newlib(L, standard); return 1; } + +static const struct luaL_Reg modules [] = { + {"bytes",luaopen_bytes}, + {"array",luaopen_array}, + {"std", luaopen_std}, + {NULL,NULL} +}; + + + +int luaopen_antd(lua_State *L) +{ + luaL_newlib(L, modules); + lua_setglobal(L, "modules"); + return 1; +} diff --git a/lib/ffi/ffi.c b/lib/asl/ffi.c similarity index 99% rename from lib/ffi/ffi.c rename to lib/asl/ffi.c index 60bd77f..db0c7f4 100644 --- a/lib/ffi/ffi.c +++ b/lib/asl/ffi.c @@ -4,7 +4,7 @@ */ #include "../lualib.h" -#include "../../lua-api.h" +//#include "../../lua-api.h" #include diff --git a/json-wrapper.c b/lib/asl/json.c similarity index 99% rename from json-wrapper.c rename to lib/asl/json.c index d1a2d13..9e158ba 100644 --- a/json-wrapper.c +++ b/lib/asl/json.c @@ -1,4 +1,4 @@ -#include "lua-api.h" +#include "../lualib.h" #include "3rd/jsmn/jsmn.h" #define MAXTOKEN 1024 diff --git a/db-wrapper.c b/lib/asl/sqlitedb.c similarity index 94% rename from db-wrapper.c rename to lib/asl/sqlitedb.c index 6e6ce22..ef49ac1 100644 --- a/db-wrapper.c +++ b/lib/asl/sqlitedb.c @@ -1,5 +1,5 @@ #include -#include "lua-api.h" +#include "../lualib.h" typedef sqlite3* sqldb; //sqldb db = NULL; @@ -8,7 +8,7 @@ static int l_getdb (lua_State *L) { // if(db) // dbclose(db); //printf("OPEN: %s\n",s); - sqldb db = __getdb((char*)s); + sqldb db = (sqldb)database(s); if(db) lua_pushlightuserdata(L, db); else @@ -98,7 +98,7 @@ static int l_hastable(lua_State *L) return 1; } static const struct luaL_Reg sqlite [] = { - {"getdb", l_getdb}, + {"_getdb", l_getdb}, {"dbclose", l_db_close}, {"query", l_db_query}, {"lastInsertID", l_db_lastid}, @@ -107,7 +107,7 @@ static const struct luaL_Reg sqlite [] = { {NULL,NULL} }; -int luaopen_sqlite(lua_State *L) +int luaopen_sqlitedb(lua_State *L) { luaL_newlib(L, sqlite); return 1; diff --git a/lib/stmr/stmr.c b/lib/asl/stmr.c similarity index 100% rename from lib/stmr/stmr.c rename to lib/asl/stmr.c diff --git a/lib/ulib/ulib.c b/lib/asl/ulib.c similarity index 100% rename from lib/ulib/ulib.c rename to lib/asl/ulib.c diff --git a/lib/wurl/wurl.c b/lib/asl/wurl.c similarity index 99% rename from lib/wurl/wurl.c rename to lib/asl/wurl.c index 7f84890..3199f29 100644 --- a/lib/wurl/wurl.c +++ b/lib/asl/wurl.c @@ -16,7 +16,7 @@ #include #include "../lualib.h" -#include "../../lua-api.h" +//#include "../../lua-api.h" #include #define CLIENT_NAME "wurl" diff --git a/lib/core/Makefile.am b/lib/core/Makefile.am new file mode 100644 index 0000000..cc15388 --- /dev/null +++ b/lib/core/Makefile.am @@ -0,0 +1,7 @@ +EXTRA_DIST = lua-5.3.4/*.c lua-5.3.4/*.h lua-5.3.4/Makefile + +all: + cd $(top_srcdir)/lib/core/lua-5.3.4 && make linux + +clean-local: + cd $(top_srcdir)/lib/core/lua-5.3.4 && make clean \ No newline at end of file diff --git a/3rd/lua-5.3.4/lapi.c b/lib/core/lua-5.3.4/lapi.c similarity index 100% rename from 3rd/lua-5.3.4/lapi.c rename to lib/core/lua-5.3.4/lapi.c diff --git a/3rd/lua-5.3.4/lapi.h b/lib/core/lua-5.3.4/lapi.h similarity index 100% rename from 3rd/lua-5.3.4/lapi.h rename to lib/core/lua-5.3.4/lapi.h diff --git a/3rd/lua-5.3.4/lauxlib.c b/lib/core/lua-5.3.4/lauxlib.c similarity index 100% rename from 3rd/lua-5.3.4/lauxlib.c rename to lib/core/lua-5.3.4/lauxlib.c diff --git a/3rd/lua-5.3.4/lauxlib.h b/lib/core/lua-5.3.4/lauxlib.h similarity index 100% rename from 3rd/lua-5.3.4/lauxlib.h rename to lib/core/lua-5.3.4/lauxlib.h diff --git a/3rd/lua-5.3.4/lbaselib.c b/lib/core/lua-5.3.4/lbaselib.c similarity index 100% rename from 3rd/lua-5.3.4/lbaselib.c rename to lib/core/lua-5.3.4/lbaselib.c diff --git a/3rd/lua-5.3.4/lbitlib.c b/lib/core/lua-5.3.4/lbitlib.c similarity index 100% rename from 3rd/lua-5.3.4/lbitlib.c rename to lib/core/lua-5.3.4/lbitlib.c diff --git a/3rd/lua-5.3.4/lcode.c b/lib/core/lua-5.3.4/lcode.c similarity index 100% rename from 3rd/lua-5.3.4/lcode.c rename to lib/core/lua-5.3.4/lcode.c diff --git a/3rd/lua-5.3.4/lcode.h b/lib/core/lua-5.3.4/lcode.h similarity index 100% rename from 3rd/lua-5.3.4/lcode.h rename to lib/core/lua-5.3.4/lcode.h diff --git a/3rd/lua-5.3.4/lcorolib.c b/lib/core/lua-5.3.4/lcorolib.c similarity index 100% rename from 3rd/lua-5.3.4/lcorolib.c rename to lib/core/lua-5.3.4/lcorolib.c diff --git a/3rd/lua-5.3.4/lctype.c b/lib/core/lua-5.3.4/lctype.c similarity index 100% rename from 3rd/lua-5.3.4/lctype.c rename to lib/core/lua-5.3.4/lctype.c diff --git a/3rd/lua-5.3.4/lctype.h b/lib/core/lua-5.3.4/lctype.h similarity index 100% rename from 3rd/lua-5.3.4/lctype.h rename to lib/core/lua-5.3.4/lctype.h diff --git a/3rd/lua-5.3.4/ldblib.c b/lib/core/lua-5.3.4/ldblib.c similarity index 100% rename from 3rd/lua-5.3.4/ldblib.c rename to lib/core/lua-5.3.4/ldblib.c diff --git a/3rd/lua-5.3.4/ldebug.c b/lib/core/lua-5.3.4/ldebug.c similarity index 100% rename from 3rd/lua-5.3.4/ldebug.c rename to lib/core/lua-5.3.4/ldebug.c diff --git a/3rd/lua-5.3.4/ldebug.h b/lib/core/lua-5.3.4/ldebug.h similarity index 100% rename from 3rd/lua-5.3.4/ldebug.h rename to lib/core/lua-5.3.4/ldebug.h diff --git a/3rd/lua-5.3.4/ldo.c b/lib/core/lua-5.3.4/ldo.c similarity index 100% rename from 3rd/lua-5.3.4/ldo.c rename to lib/core/lua-5.3.4/ldo.c diff --git a/3rd/lua-5.3.4/ldo.h b/lib/core/lua-5.3.4/ldo.h similarity index 100% rename from 3rd/lua-5.3.4/ldo.h rename to lib/core/lua-5.3.4/ldo.h diff --git a/3rd/lua-5.3.4/ldump.c b/lib/core/lua-5.3.4/ldump.c similarity index 100% rename from 3rd/lua-5.3.4/ldump.c rename to lib/core/lua-5.3.4/ldump.c diff --git a/3rd/lua-5.3.4/lfunc.c b/lib/core/lua-5.3.4/lfunc.c similarity index 100% rename from 3rd/lua-5.3.4/lfunc.c rename to lib/core/lua-5.3.4/lfunc.c diff --git a/3rd/lua-5.3.4/lfunc.h b/lib/core/lua-5.3.4/lfunc.h similarity index 100% rename from 3rd/lua-5.3.4/lfunc.h rename to lib/core/lua-5.3.4/lfunc.h diff --git a/3rd/lua-5.3.4/lgc.c b/lib/core/lua-5.3.4/lgc.c similarity index 100% rename from 3rd/lua-5.3.4/lgc.c rename to lib/core/lua-5.3.4/lgc.c diff --git a/3rd/lua-5.3.4/lgc.h b/lib/core/lua-5.3.4/lgc.h similarity index 100% rename from 3rd/lua-5.3.4/lgc.h rename to lib/core/lua-5.3.4/lgc.h diff --git a/3rd/lua-5.3.4/linit.c b/lib/core/lua-5.3.4/linit.c similarity index 100% rename from 3rd/lua-5.3.4/linit.c rename to lib/core/lua-5.3.4/linit.c diff --git a/3rd/lua-5.3.4/liolib.c b/lib/core/lua-5.3.4/liolib.c similarity index 100% rename from 3rd/lua-5.3.4/liolib.c rename to lib/core/lua-5.3.4/liolib.c diff --git a/3rd/lua-5.3.4/llex.c b/lib/core/lua-5.3.4/llex.c similarity index 100% rename from 3rd/lua-5.3.4/llex.c rename to lib/core/lua-5.3.4/llex.c diff --git a/3rd/lua-5.3.4/llex.h b/lib/core/lua-5.3.4/llex.h similarity index 100% rename from 3rd/lua-5.3.4/llex.h rename to lib/core/lua-5.3.4/llex.h diff --git a/3rd/lua-5.3.4/llimits.h b/lib/core/lua-5.3.4/llimits.h similarity index 100% rename from 3rd/lua-5.3.4/llimits.h rename to lib/core/lua-5.3.4/llimits.h diff --git a/3rd/lua-5.3.4/lmathlib.c b/lib/core/lua-5.3.4/lmathlib.c similarity index 100% rename from 3rd/lua-5.3.4/lmathlib.c rename to lib/core/lua-5.3.4/lmathlib.c diff --git a/3rd/lua-5.3.4/lmem.c b/lib/core/lua-5.3.4/lmem.c similarity index 100% rename from 3rd/lua-5.3.4/lmem.c rename to lib/core/lua-5.3.4/lmem.c diff --git a/3rd/lua-5.3.4/lmem.h b/lib/core/lua-5.3.4/lmem.h similarity index 100% rename from 3rd/lua-5.3.4/lmem.h rename to lib/core/lua-5.3.4/lmem.h diff --git a/3rd/lua-5.3.4/loadlib.c b/lib/core/lua-5.3.4/loadlib.c similarity index 100% rename from 3rd/lua-5.3.4/loadlib.c rename to lib/core/lua-5.3.4/loadlib.c diff --git a/3rd/lua-5.3.4/lobject.c b/lib/core/lua-5.3.4/lobject.c similarity index 100% rename from 3rd/lua-5.3.4/lobject.c rename to lib/core/lua-5.3.4/lobject.c diff --git a/3rd/lua-5.3.4/lobject.h b/lib/core/lua-5.3.4/lobject.h similarity index 100% rename from 3rd/lua-5.3.4/lobject.h rename to lib/core/lua-5.3.4/lobject.h diff --git a/3rd/lua-5.3.4/lopcodes.c b/lib/core/lua-5.3.4/lopcodes.c similarity index 100% rename from 3rd/lua-5.3.4/lopcodes.c rename to lib/core/lua-5.3.4/lopcodes.c diff --git a/3rd/lua-5.3.4/lopcodes.h b/lib/core/lua-5.3.4/lopcodes.h similarity index 100% rename from 3rd/lua-5.3.4/lopcodes.h rename to lib/core/lua-5.3.4/lopcodes.h diff --git a/3rd/lua-5.3.4/loslib.c b/lib/core/lua-5.3.4/loslib.c similarity index 100% rename from 3rd/lua-5.3.4/loslib.c rename to lib/core/lua-5.3.4/loslib.c diff --git a/3rd/lua-5.3.4/lparser.c b/lib/core/lua-5.3.4/lparser.c similarity index 100% rename from 3rd/lua-5.3.4/lparser.c rename to lib/core/lua-5.3.4/lparser.c diff --git a/3rd/lua-5.3.4/lparser.h b/lib/core/lua-5.3.4/lparser.h similarity index 100% rename from 3rd/lua-5.3.4/lparser.h rename to lib/core/lua-5.3.4/lparser.h diff --git a/3rd/lua-5.3.4/lprefix.h b/lib/core/lua-5.3.4/lprefix.h similarity index 100% rename from 3rd/lua-5.3.4/lprefix.h rename to lib/core/lua-5.3.4/lprefix.h diff --git a/3rd/lua-5.3.4/lstate.c b/lib/core/lua-5.3.4/lstate.c similarity index 100% rename from 3rd/lua-5.3.4/lstate.c rename to lib/core/lua-5.3.4/lstate.c diff --git a/3rd/lua-5.3.4/lstate.h b/lib/core/lua-5.3.4/lstate.h similarity index 100% rename from 3rd/lua-5.3.4/lstate.h rename to lib/core/lua-5.3.4/lstate.h diff --git a/3rd/lua-5.3.4/lstring.c b/lib/core/lua-5.3.4/lstring.c similarity index 100% rename from 3rd/lua-5.3.4/lstring.c rename to lib/core/lua-5.3.4/lstring.c diff --git a/3rd/lua-5.3.4/lstring.h b/lib/core/lua-5.3.4/lstring.h similarity index 100% rename from 3rd/lua-5.3.4/lstring.h rename to lib/core/lua-5.3.4/lstring.h diff --git a/3rd/lua-5.3.4/lstrlib.c b/lib/core/lua-5.3.4/lstrlib.c similarity index 100% rename from 3rd/lua-5.3.4/lstrlib.c rename to lib/core/lua-5.3.4/lstrlib.c diff --git a/3rd/lua-5.3.4/ltable.c b/lib/core/lua-5.3.4/ltable.c similarity index 100% rename from 3rd/lua-5.3.4/ltable.c rename to lib/core/lua-5.3.4/ltable.c diff --git a/3rd/lua-5.3.4/ltable.h b/lib/core/lua-5.3.4/ltable.h similarity index 100% rename from 3rd/lua-5.3.4/ltable.h rename to lib/core/lua-5.3.4/ltable.h diff --git a/3rd/lua-5.3.4/ltablib.c b/lib/core/lua-5.3.4/ltablib.c similarity index 100% rename from 3rd/lua-5.3.4/ltablib.c rename to lib/core/lua-5.3.4/ltablib.c diff --git a/3rd/lua-5.3.4/ltm.c b/lib/core/lua-5.3.4/ltm.c similarity index 100% rename from 3rd/lua-5.3.4/ltm.c rename to lib/core/lua-5.3.4/ltm.c diff --git a/3rd/lua-5.3.4/ltm.h b/lib/core/lua-5.3.4/ltm.h similarity index 100% rename from 3rd/lua-5.3.4/ltm.h rename to lib/core/lua-5.3.4/ltm.h diff --git a/3rd/lua-5.3.4/lua.c b/lib/core/lua-5.3.4/lua.c similarity index 100% rename from 3rd/lua-5.3.4/lua.c rename to lib/core/lua-5.3.4/lua.c diff --git a/3rd/lua-5.3.4/lua.h b/lib/core/lua-5.3.4/lua.h similarity index 100% rename from 3rd/lua-5.3.4/lua.h rename to lib/core/lua-5.3.4/lua.h diff --git a/3rd/lua-5.3.4/lua.hpp b/lib/core/lua-5.3.4/lua.hpp similarity index 100% rename from 3rd/lua-5.3.4/lua.hpp rename to lib/core/lua-5.3.4/lua.hpp diff --git a/3rd/lua-5.3.4/luac.c b/lib/core/lua-5.3.4/luac.c similarity index 100% rename from 3rd/lua-5.3.4/luac.c rename to lib/core/lua-5.3.4/luac.c diff --git a/3rd/lua-5.3.4/luaconf.h b/lib/core/lua-5.3.4/luaconf.h similarity index 100% rename from 3rd/lua-5.3.4/luaconf.h rename to lib/core/lua-5.3.4/luaconf.h diff --git a/3rd/lua-5.3.4/lualib.h b/lib/core/lua-5.3.4/lualib.h similarity index 100% rename from 3rd/lua-5.3.4/lualib.h rename to lib/core/lua-5.3.4/lualib.h diff --git a/3rd/lua-5.3.4/lundump.c b/lib/core/lua-5.3.4/lundump.c similarity index 100% rename from 3rd/lua-5.3.4/lundump.c rename to lib/core/lua-5.3.4/lundump.c diff --git a/3rd/lua-5.3.4/lundump.h b/lib/core/lua-5.3.4/lundump.h similarity index 100% rename from 3rd/lua-5.3.4/lundump.h rename to lib/core/lua-5.3.4/lundump.h diff --git a/3rd/lua-5.3.4/lutf8lib.c b/lib/core/lua-5.3.4/lutf8lib.c similarity index 100% rename from 3rd/lua-5.3.4/lutf8lib.c rename to lib/core/lua-5.3.4/lutf8lib.c diff --git a/3rd/lua-5.3.4/lvm.c b/lib/core/lua-5.3.4/lvm.c similarity index 100% rename from 3rd/lua-5.3.4/lvm.c rename to lib/core/lua-5.3.4/lvm.c diff --git a/3rd/lua-5.3.4/lvm.h b/lib/core/lua-5.3.4/lvm.h similarity index 100% rename from 3rd/lua-5.3.4/lvm.h rename to lib/core/lua-5.3.4/lvm.h diff --git a/3rd/lua-5.3.4/lzio.c b/lib/core/lua-5.3.4/lzio.c similarity index 100% rename from 3rd/lua-5.3.4/lzio.c rename to lib/core/lua-5.3.4/lzio.c diff --git a/3rd/lua-5.3.4/lzio.h b/lib/core/lua-5.3.4/lzio.h similarity index 100% rename from 3rd/lua-5.3.4/lzio.h rename to lib/core/lua-5.3.4/lzio.h diff --git a/lib/curl b/lib/curl deleted file mode 100755 index a85ae96..0000000 Binary files a/lib/curl and /dev/null differ diff --git a/lib/ffi/Makefile.am b/lib/ffi/Makefile.am deleted file mode 100644 index af4f774..0000000 --- a/lib/ffi/Makefile.am +++ /dev/null @@ -1,4 +0,0 @@ -lib_LTLIBRARIES = ffi.la -ffi_la_LDFLAGS = -module -avoid-version -shared -lffi -ffi_la_SOURCES = ffi.c -libdir=$(prefix)/lib/lua/ \ No newline at end of file diff --git a/lib/ffi/example/Makefile b/lib/ffi/example/Makefile deleted file mode 100644 index 1576d5f..0000000 --- a/lib/ffi/example/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -CC = gcc -main: lib.o - $(CC) -shared lib.o -o libtest.so - -%.o: %.c - $(CC) -fPIC -c $< -o $@ diff --git a/lib/ffi/example/example.lua b/lib/ffi/example/example.lua deleted file mode 100644 index 575d560..0000000 --- a/lib/ffi/example/example.lua +++ /dev/null @@ -1,87 +0,0 @@ -local path = "/home/blackjack/workspace/ant-http/plugins/antd-lua-plugin/lib/ffi/example/libtest.so" -local path = "/Users/mrsang/Google Drive/ushare/cwp/ant-http/plugins/antd-lua-plugin/lib/ffi/example/libtest.so" -require("cif") -local lib = nil -local fn = nil -local rettype = nil -local argtype = nil -lib = FFI.load(path) -if lib then - -- now try to lookup for the greet function - fn = FFI.lookup(lib,"greet") - if fn then - -- now the function - -- tried to called it - rettype = FFI.atomic(FFI.type.UINT8) -- voidn - argtype = { - FFI.atomic(FFI.type.POINTER), - FFI.atomic(FFI.type.DOUBLE), - FFI.atomic(FFI.type.SINT64), - FFI.atomic(FFI.type.SINT8) - } -- pointer - -- call the function - local r = FFI.call(rettype, argtype, fn, {"hello world", 0.987, -76, 65}) - if r then - echo(r) - else - echo("HELL FAIL") - end - end - fn = FFI.lookup(lib, "test_struct") - if fn then - local struct1 = FFI.struct({ - FFI.atomic(FFI.type.UINT8), -- char - FFI.atomic(FFI.type.SINT32), -- char - FFI.atomic(FFI.type.SINT16), -- char - FFI.atomic(FFI.type.UINT8), -- char - }) - local struct = FFI.struct({ - FFI.atomic(FFI.type.UINT8), -- char - struct1, - FFI.atomic(FFI.type.SINT32), -- int - FFI.atomic(FFI.type.UINT8), -- char - }) - rettype = struct --FFI.atomic(FFI.type.DOUBLE) - echo("call with struct") - local r = FFI.call(rettype,{struct},fn,{{65, {66, 2048, -97,67},-1024, 68}}) - if r then echo(JSON.encode(r)) end - --echo(JSON.encode(FFI.meta(struct1))) - end - - fn = FFI.lookup(lib, "test_string") - if(fn) then - local buff = FFI.new(256) - FFI.call(FFI.atomic(FFI.type.VOID),{FFI.atomic(FFI.type.POINTER), FFI.atomic(FFI.type.POINTER)}, fn, {buff,"Hello world"}) - echo(FFI.string(buff)) - echo(tostring(FFI.bytearray(buff,5)[1])) - FFI.byteAtPut(buff,0, 11) - echo(tostring(FFI.byteAt(buff,0))) - - end - local size = 1024 - local struct_ptr = FFI.new(12) - local buff = FFI.new(5) - FFI.byteAtPut(buff,0,64) - FFI.byteAtPut(buff,1,65) - FFI.byteAtPut(buff,2,66) - FFI.byteAtPut(buff,3,67) - FFI.byteAtPut(buff,4,0) - FFI.byteAtPut(struct_ptr, 0, 10) - FFI.byteAtPut(struct_ptr, 1, 100) - FFI.byteAtPut(struct_ptr, 2, 0) -- pad - FFI.byteAtPut(struct_ptr, 3, 0) -- pad - FFI.byteAtPut(struct_ptr, 4, size & 0xFF) - FFI.byteAtPut(struct_ptr, 5, (size >> 8) & 0xFF) - FFI.byteAtPut(struct_ptr, 6, (size >> 16) & 0xFF) - FFI.byteAtPut(struct_ptr, 7, (size >> 24) & 0xFF) - FFI.atPutPtr(struct_ptr, 8, buff) - - fn = FFI.lookup(lib, "test_struct_ptr") - if(fn) then - echo("calling test_struct_ptr") - FFI.call(FFI.atomic(FFI.type.SINT),{FFI.atomic(FFI.type.POINTER)}, fn, {struct_ptr}) - end - - FFI.unloadAll() -end -echo("end the day") \ No newline at end of file diff --git a/lib/ffi/example/lib.c b/lib/ffi/example/lib.c deleted file mode 100644 index 09767a8..0000000 --- a/lib/ffi/example/lib.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include -char data[] = {'h', 'e','l', 'l', 'o'}; - -typedef struct{ - char a; - int b; - short c; - char d; -} inner_t; - -typedef struct{ - char a; - inner_t b; - int c; - char d; -} test_t; - -struct i2c_smbus_ioctl_data -{ - char read_write ; - uint8_t command ; - int size ; - void *data ; -} ; -char greet(const char* msg, float num, int sint, char c) -{ - printf("%s: '%f' '%d' '%c'\n", msg, num, sint, c); - return 'A'; -} - -test_t test_struct(test_t data) -{ - printf("data is '%c' '%c' '%d' '%d' '%c' '%d' '%c'\n", data.a, data.b.a, data.b.b, data.b.c, data.b.d, data.c, data.d); - return data; -} - -void test_string(char* buff, const char* a) -{ - sprintf(buff,"you say %s", a); - printf("%s\n", buff); -} - -int test_struct_ptr(struct i2c_smbus_ioctl_data* data) -{ - printf("Hello\n"); - printf("rw %d cmd %d size %d %s\n", data->read_write, data->command, data->size, (char*)data->data); - return 1; -} \ No newline at end of file diff --git a/lib/lualib.h b/lib/lualib.h index 6750643..fdf4280 100644 --- a/lib/lualib.h +++ b/lib/lualib.h @@ -7,8 +7,31 @@ #include #include -#include "../3rd/lua-5.3.4/lua.h" -#include "../3rd/lua-5.3.4/lauxlib.h" -#include "../3rd/lua-5.3.4/lualib.h" +#include +#include + +#include "core/lua-5.3.4/lua.h" +#include "core/lua-5.3.4/lauxlib.h" +#include "core/lua-5.3.4/lualib.h" + + +#define ARRAY "modules.array" +#define BYTEARRAY "modules.bytes" +// add byte array support + typedef struct{ + int size; + unsigned char data[1]; + } byte_array_t; + +typedef struct{ + int size; + double data[1]; +} array_t; +// new byte array +void lua_new_byte_array(lua_State*L, int n); +byte_array_t *l_check_barray(lua_State *L, int idx); +// new array +void lua_new_array(lua_State*L, int n); +array_t *l_check_array(lua_State *L, int idx); #endif \ No newline at end of file diff --git a/lib/stmr/Makefile.am b/lib/stmr/Makefile.am deleted file mode 100644 index cd3e188..0000000 --- a/lib/stmr/Makefile.am +++ /dev/null @@ -1,4 +0,0 @@ -lib_LTLIBRARIES = stmr.la -stmr_la_LDFLAGS = -module -avoid-version -shared -stmr_la_SOURCES = stmr.c -libdir=$(prefix)/lib/lua/ \ No newline at end of file diff --git a/lib/ulib/Makefile.am b/lib/ulib/Makefile.am deleted file mode 100644 index 58f1878..0000000 --- a/lib/ulib/Makefile.am +++ /dev/null @@ -1,5 +0,0 @@ -lib_LTLIBRARIES = ulib.la -ulib_la_LDFLAGS = -module -avoid-version -shared -ulib_la_SOURCES = 3rd/zip/zip.c ulib.c -libdir=$(prefix)/lib/lua/ -EXTRA_DIST = 3rd/zip/miniz.c 3rd/zip/zip.h \ No newline at end of file diff --git a/lib/wurl/Makefile.am b/lib/wurl/Makefile.am deleted file mode 100644 index a2f0436..0000000 --- a/lib/wurl/Makefile.am +++ /dev/null @@ -1,4 +0,0 @@ -lib_LTLIBRARIES = wurl.la -wurl_la_LDFLAGS = -module -avoid-version -shared -wurl_la_SOURCES = wurl.c -libdir=$(prefix)/lib/lua/ \ No newline at end of file diff --git a/lib/wurl/test.c b/lib/wurl/test.c deleted file mode 100644 index f78274f..0000000 --- a/lib/wurl/test.c +++ /dev/null @@ -1,539 +0,0 @@ -#include //printf -#include //memset -#include //for exit(0); -#include //For errno - the error number -#include //hostent -#include -#include -//#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define CLIENT_NAME "wurl" -#define CLIENT_HOST "192.168.9.249" -#define CONN_TIME_OUT_S 3 -#define MAX_BUFF 1024 -#define REQUEST_BOUNDARY "------wURLFormBoundaryVo4QYVaSVseFNpeK" -#define GET 0 -#define POST 1 -typedef struct{ - int type; // POST(1) or GET(0) - char* resource; // path - char* ctype; // content type, used by POST - int clen; // content length, used by POST - unsigned char* data ; -} wurl_header_t; - -/*get the ip by hostname*/ -int wurl_ip_from_hostname(const char * hostname , char* ip) -{ - struct hostent *he; - struct in_addr **addr_list; - int i; - if ( (he = gethostbyname( hostname ) ) == NULL) - { - // get the host info - herror("gethostbyname"); - return -1; - } - addr_list = (struct in_addr **) he->h_addr_list; - - for(i = 0; addr_list[i] != NULL; i++) - { - //Return the first one; - strcpy(ip , inet_ntoa(*addr_list[i]) ); - return 0; - } - return -1; -} - -/* -send a request -*/ -int wurl_request_socket(const char* ip, int port) -{ - int sockfd, bytes_read; - struct sockaddr_in dest; - - // time out setting - struct timeval timeout; - timeout.tv_sec = CONN_TIME_OUT_S; - timeout.tv_usec = 0; - if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) - { - perror("Socket"); - return -1; - } - if (setsockopt (sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,sizeof(timeout)) < 0) - perror("setsockopt failed\n"); - - if (setsockopt (sockfd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout,sizeof(timeout)) < 0) - perror("setsockopt failed\n"); - - bzero(&dest, sizeof(dest)); - dest.sin_family = AF_INET; - dest.sin_port = htons(port); - if ( inet_aton(ip, &dest.sin_addr.s_addr) == 0 ) - { - perror(ip); - close(sockfd); - return -1; - } - if ( connect(sockfd, (struct sockaddr*)&dest, sizeof(dest)) != 0 ) - { - close(sockfd); - perror("Connect"); - return -1; - } - return sockfd; -} -/* -POST %s HTTP/1.0\r\n -Host: %s\r\n -User-Agent: %s\r\n -Content-Type: %s\r\n -Content-Length: %d\r\n\r\n" - -maybe cookie support? this can cause security problem - -GET %s HTTP/1.0\r\n -Host: %s\r\n -User-Agent: %s\r\n\r\n" - -multipart -POST %s HTTP/1.1 -Host: %s -User-Agent: %s -Content-Type: multipart/form-data; boundary=----------287032381131322 -Content-Length: %d - -------------287032381131322 -Content-Disposition: form-data; name="datafile1"; filename="r.gif" -Content-Type: image/gif - -GIF87a.............,...........D..; -------------287032381131322 -Content-Disposition: form-data; name="datafile2"; filename="g.gif" -Content-Type: image/gif - -GIF87a.............,...........D..; -------------287032381131322 -Content-Disposition: form-data; name="datafile3"; filename="b.gif" -Content-Type: image/gif - -GIF87a.............,...........D..; -------------287032381131322-- -*/ - -int wurl_header(int sockfd, wurl_header_t rq) -{ - char buff[MAX_BUFF]; - if(sockfd < 0) return -1; - - if(rq.type == GET) // GET - { - send(sockfd,"GET ",4,0); - send(sockfd,rq.resource, strlen(rq.resource),0); - send(sockfd," HTTP/1.0\r\n",11,0); - } - else - { - send(sockfd,"POST ",5, 0); - send(sockfd,rq.resource, strlen(rq.resource),0); - send(sockfd," HTTP/1.0\r\n",11,0); - sprintf(buff,"Content-Type: %s\r\n", rq.ctype); - send(sockfd,buff,strlen(buff),0); - sprintf(buff,"Content-Length: %d\r\n", rq.clen); - send(sockfd,buff,strlen(buff),0); - } - // host dont need to send the host - //sprintf(buff,"Host: %s\r\n",CLIENT_HOST); - //send(sockfd,buff,strlen(buff),0); - // user agent - sprintf(buff,"User-Agent: %s\r\n",CLIENT_NAME); - send(sockfd,buff,strlen(buff),0); - // terminate request - send(sockfd,"\r\n",2,0); - - // if there is data, send out - if(rq.type == POST && rq.data) - { - send(sockfd,rq.data,rq.clen,0); - } - return 0; -} - - -// this will be removed -#define IEQU(a,b) (strcasecmp(a,b) == 0) -#define LOG(x) printf(x) -/** - * Trim a string by a character on both ends - * @param str The target string - * @param delim the delim - */ -void trim(char* str, const char delim) -{ - char * p = str; - int l = strlen(p); - - while(p[l - 1] == delim) p[--l] = 0; - while(* p && (* p) == delim ) ++p, --l; - memmove(str, p, l + 1); -} -/** - * Get extension of a file name - * @param file The file name - * @return the extension - */ -char* ext(const char* file) -{ - char* token,*ltoken = ""; - if(file == NULL) return NULL; - char* str_cpy = strdup(file); - if(strstr(str_cpy,".")<= 0) return ""; - if(*file == '.') - file++; - - while((token = strsep(&str_cpy,".")) && strlen(token)>0) {ltoken = token;} - free(str_cpy); - return ltoken; - -} -/** - * Get correct HTTP mime type of a file - * This is a minimalistic mime type list supported - * by the server - * @param file File name - * @return The HTTP Mime Type - */ -char* mime(const char* file) -{ - char * ex = ext(file); - if(IEQU(ex,"bmp")) - return "image/bmp"; - else if(IEQU(ex,"jpg") || IEQU(ex,"jpeg")) - return "image/jpeg"; - else if(IEQU(ex,"css")) - return "text/css"; - else if(IEQU(ex,"csv")) - return "text/csv"; - else if(IEQU(ex,"pdf")) - return "application/pdf"; - else if(IEQU(ex,"gif")) - return "image/gif"; - else if(IEQU(ex,"html")||(IEQU(ex,"htm"))) - return "text/html"; - else if(IEQU(ex,"json")) - return "application/json"; - else if(IEQU(ex,"js")) - return "application/javascript"; - else if(IEQU(ex,"png")) - return "image/png"; - else if(IEQU(ex,"ppm")) - return "image/x-portable-pixmap"; - else if(IEQU(ex,"rar")) - return "application/x-rar-compressed"; - else if(IEQU(ex,"tiff")) - return "image/tiff"; - else if(IEQU(ex,"tar")) - return "application/x-tar"; - else if(IEQU(ex,"txt")) - return "text/plain"; - else if(IEQU(ex,"ttf")) - return "application/x-font-ttf"; - else if(IEQU(ex,"xhtml")) - return "application/xhtml+xml"; - else if(IEQU(ex,"xml")) - return "application/xml"; - else if(IEQU(ex,"zip")) - return "application/zip"; - else if(IEQU(ex,"svg")) - return "image/svg+xml"; - else if(IEQU(ex,"eot")) - return "application/vnd.ms-fontobject"; - else if(IEQU(ex,"woff") || IEQU(ex,"woff2")) - return "application/x-font-woff"; - else if(IEQU(ex,"otf")) - return "application/x-font-otf"; - //audio - else if(IEQU(ex,"mp3")) - return "audio/mpeg"; - else - // The other type will be undestant as binary - return "application/octet-stream"; -} - -void wurl_send_files(int sockfd,char* resource, int n, char* name [], char* files[]) -{ - char buff[MAX_BUFF]; - wurl_header_t rq; - rq.type = POST; - rq.resource = resource; - // get the total size of data - int totalsize = 0; - FILE* fd; - struct stat st; - for(int i = 0; i < n; ++i) - { - if(stat(files[i], &st) != 0) continue; - totalsize += st.st_size; - } - rq.clen = totalsize; - sprintf(buff,"%s; boundary=%s","multipart/form-data",REQUEST_BOUNDARY); - rq.ctype = buff; - - // now send the header - wurl_header(sockfd,rq); - // now send the files - size_t size; - for(int i = 0; i < n; ++i) - { - fd = fopen(files[i],"rb"); - if(!fd) continue; - // first send the boundary - sprintf(buff,"%s\r\n",REQUEST_BOUNDARY); - send(sockfd, buff, strlen(buff),0); - // content disposition - sprintf(buff,"Content-Disposition: form-data; name=\"%s\"; filename=\"%s\"\r\n", - name[i],basename(files[i])); - send(sockfd,buff, strlen(buff),0); - // content type - sprintf(buff,"Content-Type: %s\r\n\r\n",mime(files[i])); - send(sockfd,buff, strlen(buff),0); - // now send the file - while(!feof(fd)) - { - size = fread(buff,1,MAX_BUFF,fd); - send(sockfd,buff,size,0); - //if(!__b(client,buffer,size)) return; - } - fclose(fd); - send(sockfd,"\r\n",2,0); - } - //end the boudary - sprintf(buff,"%s--\n",REQUEST_BOUNDARY); - send(sockfd,buff,strlen(buff),0); -} - -/** - * Read the socket request in to a buffer or size - * The data is read until the buffer is full or - * there are a carrier return character - * @param sock socket - * @param buf buffer - * @param size size of buffer - * @return number of bytes read - */ -int wurl_read_buf(int sock, char*buf,int size) -{ - int i = 0; - char c = '\0'; - int n; - while ((i < size - 1) && (c != '\n')) - { - n = recv(sock, &c, 1, 0); - if (n > 0) - { - buf[i] = c; - i++; - } - else - c = '\n'; - } - buf[i] = '\0'; - return i; -} -/* - POST example - wurl_header_t rq; - rq.resource = path; - rq.type = POST; - rq.data = "s=a&q=b#test";//"{\"name\":\"sang\"}"; - rq.clen = strlen(rq.data); - rq.ctype = "application/x-www-form-urlencoded";//"application/json"; - - if(wurl_request(hostname,port,&rq,1) == 0) - { - printf(rq.data); - } - else - { - printf("Cannot connect to host\n"); - } - - DOWNLOAD - wurl_header_t rq; - rq.resource = path; - rq.type = GET; - - if(wurl_download(hostname,port,&rq,file) == 0) - { - printf("Download sucess ful\n"); - } - else - { - printf("Cannot connect to host\n"); - } - - - upload example - // send files - char * names[2]; - names[0] = "zip"; - names[1] = "text"; - char* files[2]; - files[0] = "/Users/mrsang/tmp/Archive.zip"; - files[1] = "/Users/mrsang/tmp/test.py"; - - wurl_send_files(sock,path,2,names, files); - printf("RETURN:\n"); - size = wurl_read_buf(sock,buff, MAX_BUFF); - while(size > 0) - { - printf("%s", buff); - size = wurl_read_buf(sock,buff, MAX_BUFF); - } - close(sock); -*/ - -/* - hostname - port - header for request and respond - lazy : if 1, all data is read to the header - if 0, user has the responsibility to handler it -*/ -int wurl_request(const char* hostname, int port, wurl_header_t* header, int lazy) -{ - char ip[100]; - char buff[MAX_BUFF]; - wurl_ip_from_hostname(hostname ,ip); - int sock = wurl_request_socket(ip, port); - - if(sock <= 0) return -1; - // send header - wurl_header(sock,*header); - // read respond header - int size = wurl_read_buf(sock,buff,MAX_BUFF); - char* token; - while (size > 0 && strcmp("\r\n",buff)) - { - char* line = strdup(buff); - token = strsep(&line,":"); - trim(token,' '); - if(token != NULL &&strcasecmp(token,"Content-Type") == 0) - { - header->ctype = strsep(&line,":"); - trim(header->ctype,' '); - trim(header->ctype,'\n'); - trim(header->ctype,'\r'); - } else if(token != NULL &&strcasecmp(token,"Content-Length") == 0) - { - token = strsep(&line,":"); - trim(token,' '); - header->clen = atoi(token); - } - //if(line) free(line); - size = wurl_read_buf(sock,buff,MAX_BUFF); - } - if(header->ctype == NULL || header->clen == -1) - { - LOG("Bad data\n"); - return -1; - } - - // read data if lazy - if(lazy) - { - // read line by line, ignore content length - int total_length = 0; - char* tmp = NULL; - int CHUNK = 512; - header->data = (unsigned char*) malloc(CHUNK); - int cursize = CHUNK; - int size = wurl_read_buf(sock,buff,MAX_BUFF); - while(size > 0) - { - if(total_length+size > cursize) - { - tmp = (unsigned char*) realloc(header->data,total_length + size); - if(!tmp) - { - if(header->data) free(header->data); - break; - } - header->data = tmp; - } - memcpy(header->data+total_length,buff,size); - total_length += size; - size = wurl_read_buf(sock,buff,MAX_BUFF); - } - header->clen = total_length; - close(sock); - return 0; - } - return sock; -} - -int wurl_download(const char* hostname, int port, wurl_header_t* h, const char* to) -{ - // we will handler the data reading - int sock = wurl_request(hostname, port,h,0); - unsigned char buff[MAX_BUFF]; - if(sock < 0) return -1; - - FILE* fp = fopen(to,"wb"); - int size; - if(fp) - { - while((size = wurl_read_buf(sock,buff, MAX_BUFF)) > 0) - { - fwrite(buff, size, 1, fp); - } - fclose(fp); - } - else - { - close(sock); - return -1; - } - close(sock); - return 0; -} - -int main (int argc, char const *argv[]) -{ - if(argc < 4) - { - printf("wurl [host] [port] [path]\n"); - exit(1); - } - - char *hostname = argv[1]; - char* path = argv[3]; - int port = atoi(argv[2]); - char*file = argv[4]; - wurl_header_t rq; - rq.resource = path; - rq.type = POST; - rq.data = "s=a&q=b#test";//"{\"name\":\"sang\"}"; - rq.clen = strlen(rq.data); - rq.ctype = "application/x-www-form-urlencoded";//"application/json"; - - if(wurl_download(hostname,port,&rq,file) == 0) - { - printf("Download sucess ful\n"); - } - else - { - printf("Cannot connect to host\n"); - } - return 0; -} \ No newline at end of file diff --git a/lua-api.c b/lua-api.c index fd4ca91..2af0921 100644 --- a/lua-api.c +++ b/lua-api.c @@ -1,19 +1,11 @@ #define PLUGIN_IMPLEMENT 1 #include -#include "lua-api.h" +#include + +#include "lib/lualib.h" static void* core_handle = NULL; -static const struct luaL_Reg modules [] = { -#ifdef USE_DB - {"sqlite", luaopen_sqlite}, -#endif - {"std", luaopen_standard}, - {"JSON", luaopen_json}, - {"bytes",luaopen_barray}, - {"array",luaopen_array}, - {NULL,NULL} -}; void init() { @@ -65,8 +57,8 @@ void* handle(void* data) L = luaL_newstate(); luaL_openlibs(L); //module loader - luaL_newlib(L, modules); - lua_setglobal(L, "modules"); + //luaL_newlib(L, modules); + //lua_setglobal(L, "modules"); // set up global variable // API header lua_newtable(L); @@ -85,6 +77,10 @@ void* handle(void* data) lua_pushstring(L,"tmpdir"); lua_pushstring(L, tmpdir()); lua_settable(L,-3); + + lua_pushstring(L,"dbpath"); + lua_pushstring(L, __plugin__->dbpath); + lua_settable(L,-3); lua_setglobal(L, "__api__"); @@ -103,7 +99,7 @@ void* handle(void* data) if(is_file(apis)) if (luaL_loadfile(L, apis) || lua_pcall(L, 0, 0, 0)) { - LOG( "cannot run apis. file: %s\n", lua_tostring(L, -1)); + ERROR( "cannot start API file: [%s] %s\n", apis, lua_tostring(L, -1)); } /*if (luaL_loadfile(L, index) || lua_pcall(L, 0, 0, 0)) diff --git a/lua-api.h b/lua-api.h deleted file mode 100644 index 27df369..0000000 --- a/lua-api.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef LUA_API_H -#define LUA_API_H -#include -#include -#include -#include "3rd/lua-5.3.4/lua.h" -#include "3rd/lua-5.3.4/lauxlib.h" -#include "3rd/lua-5.3.4/lualib.h" - -#define ARRAY "modules.array" -#define BYTEARRAY "modules.bytes" -// add byte array support - typedef struct{ - int size; - unsigned char data[1]; - } byte_array_t; - -typedef struct{ - int size; - double data[1]; -} array_t; -// new byte array -void lua_new_byte_array(lua_State*L, int n); -byte_array_t *l_check_barray(lua_State *L, int idx); -// new array -void lua_new_array(lua_State*L, int n); -array_t *l_check_array(lua_State *L, int idx); - -int luaopen_standard(lua_State *L); -int luaopen_sqlite(lua_State *L); -int luaopen_json(lua_State *L); -int luaopen_array (lua_State *L); -int luaopen_barray (lua_State *L); - -#endif \ No newline at end of file