Skip to content

Commit 4b92eab

Browse files
HHHartmannmarcelstoer
authored andcommitted
Add modules struct, bit, color_utils and sjson to luac.cross (#3230)
1 parent 44e4c4a commit 4b92eab

File tree

14 files changed

+141
-42
lines changed

14 files changed

+141
-42
lines changed

app/lua/linit.c

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,63 @@ extern LROT_TABLE(math);
5959
LROT_FUNCENTRY( debug, luaopen_debug )
6060

6161
#if defined(LUA_CROSS_COMPILER)
62-
extern LROT_TABLE(base_func);
62+
63+
#define LUAC_MODULE(map) \
64+
LUALIB_API LROT_TABLE(map);
65+
66+
#define LUAC_MODULE_INIT(map, initfunc) \
67+
LUAC_MODULE(map);\
68+
LUALIB_API int initfunc(lua_State *L);
69+
70+
#ifndef __MINGW32__
71+
LUAC_MODULE(thislib) // module struct
72+
LUAC_MODULE(bit)
73+
LUAC_MODULE(color_utils)
74+
LUAC_MODULE_INIT(sjson, luaopen_sjson)
75+
LUAC_MODULE(pipe)
76+
#ifndef _MSC_VER
77+
LUAC_MODULE_INIT(pixbuf, luaopen_pixbuf)
78+
#endif
79+
#endif
80+
81+
LUAC_MODULE(base_func);
6382
LROT_BEGIN(rotables_meta, NULL, LROT_MASK_INDEX)
6483
LROT_TABENTRY( __index, base_func)
6584
LROT_END(rotables_meta, NULL, LROT_MASK_INDEX)
6685

67-
extern LROT_TABLE(oslib);
68-
extern LROT_TABLE(iolib);
86+
LUAC_MODULE(oslib);
87+
LUAC_MODULE(iolib);
6988
LROT_BEGIN(rotables, LROT_TABLEREF(rotables_meta), 0)
7089
LROT_ROM_ENTRIES
7190
LROT_TABENTRY( os, oslib )
7291
LROT_TABENTRY( io, iolib )
92+
#ifndef __MINGW32__
93+
// modules
94+
LROT_TABENTRY( struct, thislib )
95+
LROT_TABENTRY(bit, bit)
96+
LROT_TABENTRY(color_utils, color_utils)
97+
LROT_TABENTRY(sjson, sjson)
98+
LROT_TABENTRY(pipe, pipe)
99+
#ifndef _MSC_VER
100+
LROT_TABENTRY(pixbuf, pixbuf)
101+
#endif
102+
#endif
73103
LROT_END(rotables, LROT_TABLEREF(rotables_meta), 0)
74104

75105
LROT_BEGIN(lua_libs, NULL, 0)
76106
LROT_LIB_ENTRIES
77107
LROT_FUNCENTRY( io, luaopen_io )
108+
#ifndef __MINGW32__
109+
// modules
110+
LROT_FUNCENTRY(struct, NULL)
111+
LROT_FUNCENTRY(bit, NULL)
112+
LROT_FUNCENTRY(color_utils, NULL)
113+
LROT_FUNCENTRY(sjson, luaopen_sjson)
114+
LROT_FUNCENTRY(pipe, NULL)
115+
#ifndef _MSC_VER
116+
LROT_FUNCENTRY(pixbuf, luaopen_pixbuf)
117+
#endif
118+
#endif
78119
LROT_END(lua_libs, NULL, 0)
79120

80121
#else

app/lua/luac_cross/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
summary ?= @true
1010

11-
CCFLAGS:= -I. -I.. -I../../include -I../../uzlib
11+
CCFLAGS:= -I. -I.. -I../../include -I../../uzlib -I../..
1212
LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld -lm -ldl -Wl,-Map=mapfile
1313

1414
CCFLAGS += -Wall
@@ -59,12 +59,15 @@ LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c
5959
lstate.c lstring.c lstrlib.c ltable.c ltablib.c \
6060
ltm.c lundump.c lvm.c lzio.c lnodemcu.c
6161
UZSRC := uzlib_deflate.c crc32.c
62+
SJSONSRC:= jsonsl.c
63+
MODSRC := struct.c bit.c color_utils.c sjson.c pipe.c pixbuf.c
64+
#bloom.c crypto.c encoder.c (file.c)
6265

6366
#
6467
# This relies on the files being unique on the vpath
6568
#
66-
SRC := $(LUACSRC) $(LUASRC) $(UZSRC)
67-
vpath %.c .:..:../../libc:../../uzlib
69+
SRC := $(LUACSRC) $(LUASRC) $(UZSRC) $(MODSRC) $(SJSONSRC)
70+
vpath %.c .:..:../../libc:../../uzlib:../../modules:../../sjson
6871

6972
ODIR := .output/$(TARGET)/$(FLAVOR)/obj
7073

app/lua/luac_cross/luac.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,7 @@ static int pmain(lua_State* L)
291291
{
292292
luaL_openlibs(L);
293293
if (luaL_loadfile(L,execute)!=0) fatal(lua_tostring(L,-1));
294-
lua_pushstring(L, execute);
295-
if (lua_pcall(L, 1, 1, 0)) fatal(lua_tostring(L,-1));
294+
if (lua_pcall(L, 0, 1, 0)) fatal(lua_tostring(L,-1));
296295
if (!lua_isfunction(L, -1))
297296
{
298297
lua_pop(L,1);

app/lua53/host/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77
.NOTPARALLEL:
88

9-
CCFLAGS:= -I. -I.. -I../../include -I../../uzlib
9+
CCFLAGS:= -I. -I.. -I../../include -I../../uzlib -I../..
1010
LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld -lm -ldl -Wl,-Map=mapfile
1111

1212
CCFLAGS += -Wall
@@ -55,6 +55,9 @@ LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c lcorolib.c lctype.c
5555
ltable.c ltablib.c ltm.c lundump.c lutf8lib.c lvm.c \
5656
lzio.c
5757
UZSRC := uzlib_deflate.c crc32.c
58+
SJSONSRC:= jsonsl.c
59+
MODSRC := struct.c bit.c color_utils.c sjson.c pipe.c pixbuf.c
60+
#bloom.c crypto.c encoder.c (file.c)
5861

5962
TEST ?=
6063
ifeq ("$(TEST)","1")
@@ -65,8 +68,8 @@ endif # $(TEST)==1
6568
#
6669
# This relies on the files being unique on the vpath
6770
#
68-
SRC := $(LUACSRC) $(LUASRC) $(UZSRC)
69-
vpath %.c .:..:../../libc:../../uzlib
71+
SRC := $(LUACSRC) $(LUASRC) $(UZSRC) $(MODSRC) $(SJSONSRC)
72+
vpath %.c .:..:../../libc:../../uzlib:../../modules:../../sjson
7073

7174
ODIR := .output/$(TARGET)/$(FLAVOR)/obj
7275

app/lua53/linit.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,49 @@ extern LROT_TABLE(utf8);
7272
#if defined(LUA_CROSS_COMPILER)
7373

7474
/* _G __index -> rotables __index -> base_func */
75-
extern LROT_TABLE(rotables_meta);
76-
extern LROT_TABLE(base_func);
77-
75+
#define LUAC_MODULE(map) \
76+
LUALIB_API LROT_TABLE(map);
77+
78+
#define LUAC_MODULE_INIT(map, initfunc) \
79+
LUAC_MODULE(map);\
80+
LUALIB_API int initfunc(lua_State *L);
81+
82+
LUAC_MODULE(thislib) // module struct
83+
LUAC_MODULE(bit)
84+
LUAC_MODULE(color_utils)
85+
LUAC_MODULE_INIT(sjson, luaopen_sjson)
86+
LUAC_MODULE(pipe)
87+
LUAC_MODULE_INIT(pixbuf, luaopen_pixbuf)
88+
89+
LUAC_MODULE(rotables_meta);
90+
LUAC_MODULE(base_func);
7891
LROT_BEGIN(rotables_meta, NULL, LROT_MASK_INDEX)
7992
LROT_TABENTRY( __index, base_func)
8093
LROT_END(rotables_meta, NULL, LROT_MASK_INDEX)
8194

8295
LROT_BEGIN(rotables, LROT_TABLEREF(rotables_meta), 0)
8396
LROT_TABENTRY( _G, base_func)
8497
LROT_ROM_ENTRIES
98+
// modules
99+
LROT_TABENTRY( struct, thislib )
100+
LROT_TABENTRY(bit, bit)
101+
LROT_TABENTRY(color_utils, color_utils)
102+
LROT_TABENTRY(sjson, sjson)
103+
LROT_TABENTRY(pipe, pipe)
104+
LROT_TABENTRY(pixbuf, pixbuf)
85105
LROT_END(rotables, LROT_TABLEREF(rotables_meta), 0)
86106

87107
LROT_BEGIN(lua_libs, NULL, 0)
88108
LROT_LIB_ENTRIES
89109
LROT_FUNCENTRY( io, luaopen_io )
90110
LROT_FUNCENTRY( os, luaopen_os )
111+
// modules
112+
LROT_FUNCENTRY(struct, NULL)
113+
LROT_FUNCENTRY(bit, NULL)
114+
LROT_FUNCENTRY(color_utils, NULL)
115+
LROT_FUNCENTRY(sjson, luaopen_sjson)
116+
LROT_FUNCENTRY(pipe, NULL)
117+
LROT_FUNCENTRY(pixbuf, luaopen_pixbuf)
91118
LROT_END(lua_libs, NULL, 0)
92119

93120
#else /* LUA_USE_ESP */

app/modules/color_utils.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
#include "module.h"
22
#include "lauxlib.h"
33
#include "lmem.h"
4-
#include "platform.h"
54
#include <stdlib.h>
65
#include <math.h>
76
#include <string.h>
8-
#include "user_interface.h"
9-
#include "osapi.h"
107

118
#include "color_utils.h"
129

app/modules/color_utils.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
#ifndef APP_MODULES_COLOR_UTILS_H_
22
#define APP_MODULES_COLOR_UTILS_H_
33

4-
#include "module.h"
5-
#include "lauxlib.h"
6-
#include "lmem.h"
7-
#include "platform.h"
8-
#include <stdlib.h>
9-
#include <math.h>
10-
#include <string.h>
11-
#include "user_interface.h"
12-
#include "osapi.h"
4+
#include "lnodemcu.h"
135

146
/**
157
* Convert hsv to grb

app/modules/pipe.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
#include "module.h"
5252
#include "lauxlib.h"
5353
#include <string.h>
54-
#include "platform.h"
5554

5655
#define INVALID_LEN ((unsigned)-1)
5756

@@ -226,11 +225,11 @@ int pipe_create(lua_State *L) {
226225
if (!lua_isnil(L, 1)) {
227226
luaL_checktype(L, 1, LUA_TFUNCTION); /* non-nil arg1 must be a function */
228227
if (lua_isnil(L, 2)) {
229-
prio = PLATFORM_TASK_PRIORITY_MEDIUM;
228+
prio = LUA_TASK_MEDIUM;
230229
} else {
231230
prio = (int) lua_tointeger(L, 2);
232-
luaL_argcheck(L, prio >= PLATFORM_TASK_PRIORITY_LOW &&
233-
prio <= PLATFORM_TASK_PRIORITY_HIGH, 2,
231+
luaL_argcheck(L, prio >= LUA_TASK_LOW &&
232+
prio <= LUA_TASK_HIGH, 2,
234233
"invalid priority");
235234
}
236235
}

lua_modules/liquidcrystal/lc-gpio4bit.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local gpio, bit = gpio, bit --luacheck: read globals gpio bit
1+
local gpio, bit = gpio, bit
22

33
return function(bus_args)
44
local rs = bus_args.rs or 0

lua_modules/liquidcrystal/lc-gpio8bit.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local gpio, bit = gpio, bit --luacheck: read globals gpio bit
1+
local gpio, bit = gpio, bit
22

33
return function(bus_args)
44
local rs = bus_args.rs or 0

0 commit comments

Comments
 (0)