diff --git a/app/lua/linit.c b/app/lua/linit.c index 05d568409f..3547fe0fe8 100644 --- a/app/lua/linit.c +++ b/app/lua/linit.c @@ -59,22 +59,63 @@ extern LROT_TABLE(math); LROT_FUNCENTRY( debug, luaopen_debug ) #if defined(LUA_CROSS_COMPILER) -extern LROT_TABLE(base_func); + +#define LUAC_MODULE(map) \ + LUALIB_API LROT_TABLE(map); + +#define LUAC_MODULE_INIT(map, initfunc) \ + LUAC_MODULE(map);\ + LUALIB_API int initfunc(lua_State *L); + +#ifndef __MINGW32__ +LUAC_MODULE(thislib) // module struct +LUAC_MODULE(bit) +LUAC_MODULE(color_utils) +LUAC_MODULE_INIT(sjson, luaopen_sjson) +LUAC_MODULE(pipe) +#ifndef _MSC_VER +LUAC_MODULE_INIT(pixbuf, luaopen_pixbuf) +#endif +#endif + +LUAC_MODULE(base_func); LROT_BEGIN(rotables_meta, NULL, LROT_MASK_INDEX) LROT_TABENTRY( __index, base_func) LROT_END(rotables_meta, NULL, LROT_MASK_INDEX) -extern LROT_TABLE(oslib); -extern LROT_TABLE(iolib); +LUAC_MODULE(oslib); +LUAC_MODULE(iolib); LROT_BEGIN(rotables, LROT_TABLEREF(rotables_meta), 0) LROT_ROM_ENTRIES LROT_TABENTRY( os, oslib ) LROT_TABENTRY( io, iolib ) +#ifndef __MINGW32__ + // modules + LROT_TABENTRY( struct, thislib ) + LROT_TABENTRY(bit, bit) + LROT_TABENTRY(color_utils, color_utils) + LROT_TABENTRY(sjson, sjson) + LROT_TABENTRY(pipe, pipe) +#ifndef _MSC_VER + LROT_TABENTRY(pixbuf, pixbuf) +#endif +#endif LROT_END(rotables, LROT_TABLEREF(rotables_meta), 0) LROT_BEGIN(lua_libs, NULL, 0) LROT_LIB_ENTRIES LROT_FUNCENTRY( io, luaopen_io ) +#ifndef __MINGW32__ + // modules + LROT_FUNCENTRY(struct, NULL) + LROT_FUNCENTRY(bit, NULL) + LROT_FUNCENTRY(color_utils, NULL) + LROT_FUNCENTRY(sjson, luaopen_sjson) + LROT_FUNCENTRY(pipe, NULL) +#ifndef _MSC_VER + LROT_FUNCENTRY(pixbuf, luaopen_pixbuf) +#endif +#endif LROT_END(lua_libs, NULL, 0) #else diff --git a/app/lua/luac_cross/Makefile b/app/lua/luac_cross/Makefile index e617da739f..19021ac947 100644 --- a/app/lua/luac_cross/Makefile +++ b/app/lua/luac_cross/Makefile @@ -8,7 +8,7 @@ summary ?= @true -CCFLAGS:= -I. -I.. -I../../include -I../../uzlib +CCFLAGS:= -I. -I.. -I../../include -I../../uzlib -I../.. LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld -lm -ldl -Wl,-Map=mapfile CCFLAGS += -Wall @@ -59,12 +59,15 @@ LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c \ ltm.c lundump.c lvm.c lzio.c lnodemcu.c UZSRC := uzlib_deflate.c crc32.c +SJSONSRC:= jsonsl.c +MODSRC := struct.c bit.c color_utils.c sjson.c pipe.c pixbuf.c +#bloom.c crypto.c encoder.c (file.c) # # This relies on the files being unique on the vpath # -SRC := $(LUACSRC) $(LUASRC) $(UZSRC) -vpath %.c .:..:../../libc:../../uzlib +SRC := $(LUACSRC) $(LUASRC) $(UZSRC) $(MODSRC) $(SJSONSRC) +vpath %.c .:..:../../libc:../../uzlib:../../modules:../../sjson ODIR := .output/$(TARGET)/$(FLAVOR)/obj diff --git a/app/lua/luac_cross/luac.c b/app/lua/luac_cross/luac.c index 45f302caeb..baaa8b2649 100644 --- a/app/lua/luac_cross/luac.c +++ b/app/lua/luac_cross/luac.c @@ -291,8 +291,7 @@ static int pmain(lua_State* L) { luaL_openlibs(L); if (luaL_loadfile(L,execute)!=0) fatal(lua_tostring(L,-1)); - lua_pushstring(L, execute); - if (lua_pcall(L, 1, 1, 0)) fatal(lua_tostring(L,-1)); + if (lua_pcall(L, 0, 1, 0)) fatal(lua_tostring(L,-1)); if (!lua_isfunction(L, -1)) { lua_pop(L,1); diff --git a/app/lua53/host/Makefile b/app/lua53/host/Makefile index b83ef275c3..5b3ffc0624 100644 --- a/app/lua53/host/Makefile +++ b/app/lua53/host/Makefile @@ -6,7 +6,7 @@ # .NOTPARALLEL: -CCFLAGS:= -I. -I.. -I../../include -I../../uzlib +CCFLAGS:= -I. -I.. -I../../include -I../../uzlib -I../.. LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld -lm -ldl -Wl,-Map=mapfile CCFLAGS += -Wall @@ -55,6 +55,9 @@ LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c lcorolib.c lctype.c ltable.c ltablib.c ltm.c lundump.c lutf8lib.c lvm.c \ lzio.c UZSRC := uzlib_deflate.c crc32.c +SJSONSRC:= jsonsl.c +MODSRC := struct.c bit.c color_utils.c sjson.c pipe.c pixbuf.c +#bloom.c crypto.c encoder.c (file.c) TEST ?= ifeq ("$(TEST)","1") @@ -65,8 +68,8 @@ endif # $(TEST)==1 # # This relies on the files being unique on the vpath # -SRC := $(LUACSRC) $(LUASRC) $(UZSRC) -vpath %.c .:..:../../libc:../../uzlib +SRC := $(LUACSRC) $(LUASRC) $(UZSRC) $(MODSRC) $(SJSONSRC) +vpath %.c .:..:../../libc:../../uzlib:../../modules:../../sjson ODIR := .output/$(TARGET)/$(FLAVOR)/obj diff --git a/app/lua53/linit.c b/app/lua53/linit.c index 1538ce6ef2..2776df54a7 100644 --- a/app/lua53/linit.c +++ b/app/lua53/linit.c @@ -72,9 +72,22 @@ extern LROT_TABLE(utf8); #if defined(LUA_CROSS_COMPILER) /* _G __index -> rotables __index -> base_func */ -extern LROT_TABLE(rotables_meta); -extern LROT_TABLE(base_func); - +#define LUAC_MODULE(map) \ + LUALIB_API LROT_TABLE(map); + +#define LUAC_MODULE_INIT(map, initfunc) \ + LUAC_MODULE(map);\ + LUALIB_API int initfunc(lua_State *L); + +LUAC_MODULE(thislib) // module struct +LUAC_MODULE(bit) +LUAC_MODULE(color_utils) +LUAC_MODULE_INIT(sjson, luaopen_sjson) +LUAC_MODULE(pipe) +LUAC_MODULE_INIT(pixbuf, luaopen_pixbuf) + +LUAC_MODULE(rotables_meta); +LUAC_MODULE(base_func); LROT_BEGIN(rotables_meta, NULL, LROT_MASK_INDEX) LROT_TABENTRY( __index, base_func) LROT_END(rotables_meta, NULL, LROT_MASK_INDEX) @@ -82,12 +95,26 @@ LROT_END(rotables_meta, NULL, LROT_MASK_INDEX) LROT_BEGIN(rotables, LROT_TABLEREF(rotables_meta), 0) LROT_TABENTRY( _G, base_func) LROT_ROM_ENTRIES + // modules + LROT_TABENTRY( struct, thislib ) + LROT_TABENTRY(bit, bit) + LROT_TABENTRY(color_utils, color_utils) + LROT_TABENTRY(sjson, sjson) + LROT_TABENTRY(pipe, pipe) + LROT_TABENTRY(pixbuf, pixbuf) LROT_END(rotables, LROT_TABLEREF(rotables_meta), 0) LROT_BEGIN(lua_libs, NULL, 0) LROT_LIB_ENTRIES LROT_FUNCENTRY( io, luaopen_io ) LROT_FUNCENTRY( os, luaopen_os ) + // modules + LROT_FUNCENTRY(struct, NULL) + LROT_FUNCENTRY(bit, NULL) + LROT_FUNCENTRY(color_utils, NULL) + LROT_FUNCENTRY(sjson, luaopen_sjson) + LROT_FUNCENTRY(pipe, NULL) + LROT_FUNCENTRY(pixbuf, luaopen_pixbuf) LROT_END(lua_libs, NULL, 0) #else /* LUA_USE_ESP */ diff --git a/app/modules/color_utils.c b/app/modules/color_utils.c index fd63da82ee..be405ef4d5 100644 --- a/app/modules/color_utils.c +++ b/app/modules/color_utils.c @@ -1,12 +1,9 @@ #include "module.h" #include "lauxlib.h" #include "lmem.h" -#include "platform.h" #include #include #include -#include "user_interface.h" -#include "osapi.h" #include "color_utils.h" diff --git a/app/modules/color_utils.h b/app/modules/color_utils.h index 42a911b1f8..2d81d36293 100644 --- a/app/modules/color_utils.h +++ b/app/modules/color_utils.h @@ -1,15 +1,7 @@ #ifndef APP_MODULES_COLOR_UTILS_H_ #define APP_MODULES_COLOR_UTILS_H_ -#include "module.h" -#include "lauxlib.h" -#include "lmem.h" -#include "platform.h" -#include -#include -#include -#include "user_interface.h" -#include "osapi.h" +#include "lnodemcu.h" /** * Convert hsv to grb diff --git a/app/modules/pipe.c b/app/modules/pipe.c index c46770af42..aebfd80b44 100644 --- a/app/modules/pipe.c +++ b/app/modules/pipe.c @@ -51,7 +51,6 @@ #include "module.h" #include "lauxlib.h" #include -#include "platform.h" #define INVALID_LEN ((unsigned)-1) @@ -226,11 +225,11 @@ int pipe_create(lua_State *L) { if (!lua_isnil(L, 1)) { luaL_checktype(L, 1, LUA_TFUNCTION); /* non-nil arg1 must be a function */ if (lua_isnil(L, 2)) { - prio = PLATFORM_TASK_PRIORITY_MEDIUM; + prio = LUA_TASK_MEDIUM; } else { prio = (int) lua_tointeger(L, 2); - luaL_argcheck(L, prio >= PLATFORM_TASK_PRIORITY_LOW && - prio <= PLATFORM_TASK_PRIORITY_HIGH, 2, + luaL_argcheck(L, prio >= LUA_TASK_LOW && + prio <= LUA_TASK_HIGH, 2, "invalid priority"); } } diff --git a/lua_modules/liquidcrystal/lc-gpio4bit.lua b/lua_modules/liquidcrystal/lc-gpio4bit.lua index 9870bfa0ab..4a682dbc62 100644 --- a/lua_modules/liquidcrystal/lc-gpio4bit.lua +++ b/lua_modules/liquidcrystal/lc-gpio4bit.lua @@ -1,4 +1,4 @@ -local gpio, bit = gpio, bit --luacheck: read globals gpio bit +local gpio, bit = gpio, bit return function(bus_args) local rs = bus_args.rs or 0 diff --git a/lua_modules/liquidcrystal/lc-gpio8bit.lua b/lua_modules/liquidcrystal/lc-gpio8bit.lua index cd38a7e050..43b7ffd37c 100644 --- a/lua_modules/liquidcrystal/lc-gpio8bit.lua +++ b/lua_modules/liquidcrystal/lc-gpio8bit.lua @@ -1,4 +1,4 @@ -local gpio, bit = gpio, bit --luacheck: read globals gpio bit +local gpio, bit = gpio, bit return function(bus_args) local rs = bus_args.rs or 0 diff --git a/lua_modules/liquidcrystal/lc-i2c4bit.lua b/lua_modules/liquidcrystal/lc-i2c4bit.lua index 0d286a02ae..5527c00c51 100644 --- a/lua_modules/liquidcrystal/lc-i2c4bit.lua +++ b/lua_modules/liquidcrystal/lc-i2c4bit.lua @@ -1,4 +1,4 @@ -local i2c, bit = i2c, bit --luacheck: read globals i2c bit +local i2c, bit = i2c, bit return function(bus_args) local busid = bus_args.id or 0 diff --git a/lua_modules/liquidcrystal/liquidcrystal.lua b/lua_modules/liquidcrystal/liquidcrystal.lua index ce13834b85..d711e57a28 100644 --- a/lua_modules/liquidcrystal/liquidcrystal.lua +++ b/lua_modules/liquidcrystal/liquidcrystal.lua @@ -1,4 +1,4 @@ -local bit = bit --luacheck: read globals bit +local bit = bit -- metatable local LiquidCrystal = {} LiquidCrystal.__index = LiquidCrystal diff --git a/msvc/luac-cross/luac-cross.vcxproj b/msvc/luac-cross/luac-cross.vcxproj index 546a800ed2..1bad4dcc7f 100644 --- a/msvc/luac-cross/luac-cross.vcxproj +++ b/msvc/luac-cross/luac-cross.vcxproj @@ -104,7 +104,7 @@ true pch.h MultiThreadedDebug - $(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib + $(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib;$(ProjectDir)\..\..\app Console @@ -123,7 +123,7 @@ true pch.h MultiThreadedDebug - $(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib + $(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib;$(ProjectDir)\..\..\app Console @@ -144,7 +144,7 @@ true pch.h MultiThreaded - $(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib + $(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib;$(ProjectDir)\..\..\app Console @@ -167,7 +167,7 @@ true pch.h MultiThreaded - $(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib + $(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib;$(ProjectDir)\..\..\app Console @@ -212,6 +212,12 @@ + + + + + + @@ -246,6 +252,9 @@ + + + diff --git a/msvc/luac-cross/luac-cross.vcxproj.filters b/msvc/luac-cross/luac-cross.vcxproj.filters index 2b3aebb8e3..5cdef7c103 100644 --- a/msvc/luac-cross/luac-cross.vcxproj.filters +++ b/msvc/luac-cross/luac-cross.vcxproj.filters @@ -1,10 +1,6 @@ - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - {93995380-89BD-4b04-88EB-625FBE52EBFB} h;hh;hpp;hxx;hm;inl;inc;ipp;xsd @@ -28,6 +24,12 @@ {439d70e8-0091-42d2-919f-7e710de3867c} + + {3b52796e-cc0c-458d-bb40-d416bb18d49d} + + + {fcd87750-9084-4308-bb91-bd4d44d29a90} + @@ -132,6 +134,24 @@ app\lua + + app\modules + + + app\modules + + + app\modules + + + app\modules + + + app\modules + + + app\sjson + app\lua @@ -230,5 +250,14 @@ app\include + + app\sjson + + + app\sjson + + + app\sjson +