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

+44-3
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

+6-3
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

+1-2
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

+6-3
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

+30-3
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

-3
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

+1-9
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

+3-4
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

+1-1
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

+1-1
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-i2c4bit.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local i2c, bit = i2c, bit --luacheck: read globals i2c bit
1+
local i2c, bit = i2c, bit
22

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

lua_modules/liquidcrystal/liquidcrystal.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local bit = bit --luacheck: read globals bit
1+
local bit = bit
22
-- metatable
33
local LiquidCrystal = {}
44
LiquidCrystal.__index = LiquidCrystal

msvc/luac-cross/luac-cross.vcxproj

+13-4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
<ConformanceMode>true</ConformanceMode>
105105
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
106106
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
107-
<AdditionalIncludeDirectories>$(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib</AdditionalIncludeDirectories>
107+
<AdditionalIncludeDirectories>$(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib;$(ProjectDir)\..\..\app</AdditionalIncludeDirectories>
108108
</ClCompile>
109109
<Link>
110110
<SubSystem>Console</SubSystem>
@@ -123,7 +123,7 @@
123123
<ConformanceMode>true</ConformanceMode>
124124
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
125125
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
126-
<AdditionalIncludeDirectories>$(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib</AdditionalIncludeDirectories>
126+
<AdditionalIncludeDirectories>$(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib;$(ProjectDir)\..\..\app</AdditionalIncludeDirectories>
127127
</ClCompile>
128128
<Link>
129129
<SubSystem>Console</SubSystem>
@@ -144,7 +144,7 @@
144144
<ConformanceMode>true</ConformanceMode>
145145
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
146146
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
147-
<AdditionalIncludeDirectories>$(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib</AdditionalIncludeDirectories>
147+
<AdditionalIncludeDirectories>$(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib;$(ProjectDir)\..\..\app</AdditionalIncludeDirectories>
148148
</ClCompile>
149149
<Link>
150150
<SubSystem>Console</SubSystem>
@@ -167,7 +167,7 @@
167167
<ConformanceMode>true</ConformanceMode>
168168
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
169169
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
170-
<AdditionalIncludeDirectories>$(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib</AdditionalIncludeDirectories>
170+
<AdditionalIncludeDirectories>$(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib;$(ProjectDir)\..\..\app</AdditionalIncludeDirectories>
171171
</ClCompile>
172172
<Link>
173173
<SubSystem>Console</SubSystem>
@@ -212,6 +212,12 @@
212212
<ClCompile Include="..\..\app\lua\lundump.c" />
213213
<ClCompile Include="..\..\app\lua\lvm.c" />
214214
<ClCompile Include="..\..\app\lua\lzio.c" />
215+
<ClCompile Include="..\..\app\modules\bit.c" />
216+
<ClCompile Include="..\..\app\modules\color_utils.c" />
217+
<ClCompile Include="..\..\app\modules\sjson.c" />
218+
<ClCompile Include="..\..\app\modules\pipe.c" />
219+
<ClCompile Include="..\..\app\modules\struct.c" />
220+
<ClCompile Include="..\..\app\sjson\jsonsl.c" />
215221
<ClCompile Include="..\..\app\uzlib\crc32.c" />
216222
<ClCompile Include="..\..\app\uzlib\uzlib_deflate.c" />
217223
</ItemGroup>
@@ -246,6 +252,9 @@
246252
<ClInclude Include="..\..\app\lua\lundump.h" />
247253
<ClInclude Include="..\..\app\lua\lvm.h" />
248254
<ClInclude Include="..\..\app\lua\lzio.h" />
255+
<ClInclude Include="..\..\app\sjson\jsonsl.h" />
256+
<ClInclude Include="..\..\app\sjson\json_config.h" />
257+
<ClInclude Include="..\..\app\sjson\memcompat.h" />
249258
<ClInclude Include="..\..\app\uzlib\uzlib.h" />
250259
</ItemGroup>
251260
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

msvc/luac-cross/luac-cross.vcxproj.filters

+33-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup>
4-
<Filter Include="Source Files">
5-
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6-
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7-
</Filter>
84
<Filter Include="Header Files">
95
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
106
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
@@ -28,6 +24,12 @@
2824
<Filter Include="app\include">
2925
<UniqueIdentifier>{439d70e8-0091-42d2-919f-7e710de3867c}</UniqueIdentifier>
3026
</Filter>
27+
<Filter Include="app\modules">
28+
<UniqueIdentifier>{3b52796e-cc0c-458d-bb40-d416bb18d49d}</UniqueIdentifier>
29+
</Filter>
30+
<Filter Include="app\sjson">
31+
<UniqueIdentifier>{fcd87750-9084-4308-bb91-bd4d44d29a90}</UniqueIdentifier>
32+
</Filter>
3133
</ItemGroup>
3234
<ItemGroup>
3335
<ClCompile Include="..\..\app\uzlib\crc32.c">
@@ -132,6 +134,24 @@
132134
<ClCompile Include="..\..\app\lua\lzio.c">
133135
<Filter>app\lua</Filter>
134136
</ClCompile>
137+
<ClCompile Include="..\..\app\modules\struct.c">
138+
<Filter>app\modules</Filter>
139+
</ClCompile>
140+
<ClCompile Include="..\..\app\modules\bit.c">
141+
<Filter>app\modules</Filter>
142+
</ClCompile>
143+
<ClCompile Include="..\..\app\modules\color_utils.c">
144+
<Filter>app\modules</Filter>
145+
</ClCompile>
146+
<ClCompile Include="..\..\app\modules\sjson.c">
147+
<Filter>app\modules</Filter>
148+
</ClCompile>
149+
<ClCompile Include="..\..\app\modules\pipe.c">
150+
<Filter>app\modules</Filter>
151+
</ClCompile>
152+
<ClCompile Include="..\..\app\sjson\jsonsl.c">
153+
<Filter>app\sjson</Filter>
154+
</ClCompile>
135155
<ClCompile Include="..\..\app\lua\lnodemcu.c">
136156
<Filter>app\lua</Filter>
137157
</ClCompile>
@@ -230,5 +250,14 @@
230250
<ClInclude Include="..\..\app\include\user_modules.h">
231251
<Filter>app\include</Filter>
232252
</ClInclude>
253+
<ClInclude Include="..\..\app\sjson\json_config.h">
254+
<Filter>app\sjson</Filter>
255+
</ClInclude>
256+
<ClInclude Include="..\..\app\sjson\jsonsl.h">
257+
<Filter>app\sjson</Filter>
258+
</ClInclude>
259+
<ClInclude Include="..\..\app\sjson\memcompat.h">
260+
<Filter>app\sjson</Filter>
261+
</ClInclude>
233262
</ItemGroup>
234263
</Project>

0 commit comments

Comments
 (0)