Commit bbeb09b6 authored by Terry Ellison's avatar Terry Ellison Committed by Marcel Stör
Browse files

Squashed updates do get Lua51 and Lua53 working (#3075)

-  Lots of minor but nasty bugfixes to get all tests to run clean
-  core lua and test suite fixes to allow luac -F to run cleanly against test suite
-  next tranch to get LFS working
-  luac.cross -a options plus fixes from feedback
-  UART fixes and lua.c merge
-  commit of wip prior to rebaselining against current dev
-  more tweaks
parent 99aba344
...@@ -83,9 +83,9 @@ static int ICACHE_FLASH_ATTR rc_send(lua_State* L) { ...@@ -83,9 +83,9 @@ static int ICACHE_FLASH_ATTR rc_send(lua_State* L) {
} }
// Module function map // Module function map
LROT_BEGIN(rc) LROT_BEGIN(rc, NULL, 0)
LROT_FUNCENTRY( send, rc_send ) LROT_FUNCENTRY( send, rc_send )
LROT_END( rc, NULL, 0 ) LROT_END(rc, NULL, 0)
int luaopen_rc(lua_State *L) { int luaopen_rc(lua_State *L) {
......
...@@ -102,9 +102,9 @@ static int rfswitch_send( lua_State *L ) ...@@ -102,9 +102,9 @@ static int rfswitch_send( lua_State *L )
} }
// Module function map // Module function map
LROT_BEGIN(rfswitch) LROT_BEGIN(rfswitch, NULL, 0)
LROT_FUNCENTRY( send, rfswitch_send ) LROT_FUNCENTRY( send, rfswitch_send )
LROT_END( rfswitch, NULL, 0 ) LROT_END(rfswitch, NULL, 0)
NODEMCU_MODULE(RFSWITCH, "rfswitch", rfswitch, NULL); NODEMCU_MODULE(RFSWITCH, "rfswitch", rfswitch, NULL);
...@@ -80,7 +80,7 @@ static void callback_free(lua_State* L, unsigned int id, int mask) ...@@ -80,7 +80,7 @@ static void callback_free(lua_State* L, unsigned int id, int mask)
static int callback_setOne(lua_State* L, int *cb_ptr, int arg_number) static int callback_setOne(lua_State* L, int *cb_ptr, int arg_number)
{ {
if (lua_type(L, arg_number) == LUA_TFUNCTION || lua_type(L, arg_number) == LUA_TLIGHTFUNCTION) { if (lua_isfunction(L, arg_number)) {
lua_pushvalue(L, arg_number); // copy argument (func) to the top of stack lua_pushvalue(L, arg_number); // copy argument (func) to the top of stack
callback_free_one(L, cb_ptr); callback_free_one(L, cb_ptr);
*cb_ptr = luaL_ref(L, LUA_REGISTRYINDEX); *cb_ptr = luaL_ref(L, LUA_REGISTRYINDEX);
...@@ -396,7 +396,7 @@ static int rotary_open(lua_State *L) ...@@ -396,7 +396,7 @@ static int rotary_open(lua_State *L)
} }
// Module function map // Module function map
LROT_BEGIN(rotary) LROT_BEGIN(rotary, NULL, 0)
LROT_FUNCENTRY( setup, lrotary_setup ) LROT_FUNCENTRY( setup, lrotary_setup )
LROT_FUNCENTRY( close, lrotary_close ) LROT_FUNCENTRY( close, lrotary_close )
LROT_FUNCENTRY( on, lrotary_on ) LROT_FUNCENTRY( on, lrotary_on )
...@@ -409,7 +409,7 @@ LROT_BEGIN(rotary) ...@@ -409,7 +409,7 @@ LROT_BEGIN(rotary)
LROT_NUMENTRY( DBLCLICK, MASK(DBLCLICK) ) LROT_NUMENTRY( DBLCLICK, MASK(DBLCLICK) )
LROT_NUMENTRY( ALL, ROTARY_ALL ) LROT_NUMENTRY( ALL, ROTARY_ALL )
LROT_END( rotary, NULL, 0 ) LROT_END(rotary, NULL, 0)
NODEMCU_MODULE(ROTARY, "rotary", rotary, rotary_open); NODEMCU_MODULE(ROTARY, "rotary", rotary, rotary_open);
...@@ -166,7 +166,7 @@ static int rtcfifo_dsleep_until_sample (lua_State *L) ...@@ -166,7 +166,7 @@ static int rtcfifo_dsleep_until_sample (lua_State *L)
#endif #endif
// Module function map // Module function map
LROT_BEGIN(rtcfifo) LROT_BEGIN(rtcfifo, NULL, 0)
LROT_FUNCENTRY( prepare, rtcfifo_prepare ) LROT_FUNCENTRY( prepare, rtcfifo_prepare )
LROT_FUNCENTRY( ready, rtcfifo_ready ) LROT_FUNCENTRY( ready, rtcfifo_ready )
LROT_FUNCENTRY( put, rtcfifo_put ) LROT_FUNCENTRY( put, rtcfifo_put )
...@@ -177,7 +177,7 @@ LROT_BEGIN(rtcfifo) ...@@ -177,7 +177,7 @@ LROT_BEGIN(rtcfifo)
#ifdef LUA_USE_MODULES_RTCTIME #ifdef LUA_USE_MODULES_RTCTIME
LROT_FUNCENTRY( dsleep_until_sample, rtcfifo_dsleep_until_sample ) LROT_FUNCENTRY( dsleep_until_sample, rtcfifo_dsleep_until_sample )
#endif #endif
LROT_END( rtcfifo, NULL, 0 ) LROT_END(rtcfifo, NULL, 0)
NODEMCU_MODULE(RTCFIFO, "rtcfifo", rtcfifo, NULL); NODEMCU_MODULE(RTCFIFO, "rtcfifo", rtcfifo, NULL);
...@@ -41,10 +41,10 @@ static int rtcmem_write32 (lua_State *L) ...@@ -41,10 +41,10 @@ static int rtcmem_write32 (lua_State *L)
// Module function map // Module function map
LROT_BEGIN(rtcmem) LROT_BEGIN(rtcmem, NULL, 0)
LROT_FUNCENTRY( read32, rtcmem_read32 ) LROT_FUNCENTRY( read32, rtcmem_read32 )
LROT_FUNCENTRY( write32, rtcmem_write32 ) LROT_FUNCENTRY( write32, rtcmem_write32 )
LROT_END( rtcmem, NULL, 0 ) LROT_END(rtcmem, NULL, 0)
NODEMCU_MODULE(RTCMEM, "rtcmem", rtcmem, NULL); NODEMCU_MODULE(RTCMEM, "rtcmem", rtcmem, NULL);
...@@ -228,14 +228,14 @@ static int rtctime_epoch2cal (lua_State *L) ...@@ -228,14 +228,14 @@ static int rtctime_epoch2cal (lua_State *L)
} }
// Module function map // Module function map
LROT_BEGIN(rtctime) LROT_BEGIN(rtctime, NULL, 0)
LROT_FUNCENTRY( set, rtctime_set ) LROT_FUNCENTRY( set, rtctime_set )
LROT_FUNCENTRY( get, rtctime_get ) LROT_FUNCENTRY( get, rtctime_get )
LROT_FUNCENTRY( adjust_delta, rtctime_adjust_delta ) LROT_FUNCENTRY( adjust_delta, rtctime_adjust_delta )
LROT_FUNCENTRY( dsleep, rtctime_dsleep ) LROT_FUNCENTRY( dsleep, rtctime_dsleep )
LROT_FUNCENTRY( dsleep_aligned, rtctime_dsleep_aligned ) LROT_FUNCENTRY( dsleep_aligned, rtctime_dsleep_aligned )
LROT_FUNCENTRY( epoch2cal, rtctime_epoch2cal ) LROT_FUNCENTRY( epoch2cal, rtctime_epoch2cal )
LROT_END( rtctime, NULL, 0 ) LROT_END(rtctime, NULL, 0)
NODEMCU_MODULE(RTCTIME, "rtctime", rtctime, NULL); NODEMCU_MODULE(RTCTIME, "rtctime", rtctime, NULL);
...@@ -247,7 +247,7 @@ static int si7021_lua_firmware(lua_State* L) { ...@@ -247,7 +247,7 @@ static int si7021_lua_firmware(lua_State* L) {
return 1; return 1;
} }
LROT_BEGIN(si7021) LROT_BEGIN(si7021, NULL, 0)
LROT_FUNCENTRY( setup, si7021_lua_setup ) LROT_FUNCENTRY( setup, si7021_lua_setup )
LROT_FUNCENTRY( setting, si7021_lua_setting ) LROT_FUNCENTRY( setting, si7021_lua_setting )
LROT_FUNCENTRY( read, si7021_lua_read ) LROT_FUNCENTRY( read, si7021_lua_read )
...@@ -259,7 +259,7 @@ LROT_BEGIN(si7021) ...@@ -259,7 +259,7 @@ LROT_BEGIN(si7021)
LROT_NUMENTRY( RH11_TEMP11, SI7021_RH11_TEMP11 ) LROT_NUMENTRY( RH11_TEMP11, SI7021_RH11_TEMP11 )
LROT_NUMENTRY( HEATER_ENABLE, SI7021_HEATER_ENABLE ) LROT_NUMENTRY( HEATER_ENABLE, SI7021_HEATER_ENABLE )
LROT_NUMENTRY( HEATER_DISABLE, SI7021_HEATER_DISABLE ) LROT_NUMENTRY( HEATER_DISABLE, SI7021_HEATER_DISABLE )
LROT_END( si7021, NULL, 0 ) LROT_END(si7021, NULL, 0)
NODEMCU_MODULE(SI7021, "si7021", si7021, NULL); NODEMCU_MODULE(SI7021, "si7021", si7021, NULL);
...@@ -74,13 +74,13 @@ static int sigma_delta_settarget( lua_State *L ) ...@@ -74,13 +74,13 @@ static int sigma_delta_settarget( lua_State *L )
// Module function map // Module function map
LROT_BEGIN(sigma_delta) LROT_BEGIN(sigma_delta, NULL, 0)
LROT_FUNCENTRY( setup, sigma_delta_setup ) LROT_FUNCENTRY( setup, sigma_delta_setup )
LROT_FUNCENTRY( close, sigma_delta_close ) LROT_FUNCENTRY( close, sigma_delta_close )
LROT_FUNCENTRY( setpwmduty, sigma_delta_setpwmduty ) LROT_FUNCENTRY( setpwmduty, sigma_delta_setpwmduty )
LROT_FUNCENTRY( setprescale, sigma_delta_setprescale ) LROT_FUNCENTRY( setprescale, sigma_delta_setprescale )
LROT_FUNCENTRY( settarget, sigma_delta_settarget ) LROT_FUNCENTRY( settarget, sigma_delta_settarget )
LROT_END( sigma_delta, NULL, 0 ) LROT_END(sigma_delta, NULL, 0)
NODEMCU_MODULE(SIGMA_DELTA, "sigma_delta", sigma_delta, NULL); NODEMCU_MODULE(SIGMA_DELTA, "sigma_delta", sigma_delta, NULL);
#define LUA_LIB #define LUA_LIB
#include "lua.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "lstring.h" #include "lstring.h"
...@@ -93,7 +92,7 @@ create_new_element(jsonsl_t jsn, ...@@ -93,7 +92,7 @@ create_new_element(jsonsl_t jsn,
case JSONSL_T_LIST: case JSONSL_T_LIST:
case JSONSL_T_OBJECT: case JSONSL_T_OBJECT:
create_table(data); create_table(data);
state->lua_object_ref = lua_ref(data->L, 1); state->lua_object_ref = luaL_ref(data->L, LUA_REGISTRYINDEX);
state->used_count = 0; state->used_count = 0;
lua_rawgeti(data->L, LUA_REGISTRYINDEX, get_parent_object_ref()); lua_rawgeti(data->L, LUA_REGISTRYINDEX, get_parent_object_ref());
...@@ -104,7 +103,7 @@ create_new_element(jsonsl_t jsn, ...@@ -104,7 +103,7 @@ create_new_element(jsonsl_t jsn,
} else { } else {
// object, so // object, so
lua_rawgeti(data->L, LUA_REGISTRYINDEX, data->hkey_ref); lua_rawgeti(data->L, LUA_REGISTRYINDEX, data->hkey_ref);
lua_unref(data->L, data->hkey_ref); luaL_unref(data->L, LUA_REGISTRYINDEX, data->hkey_ref);
data->hkey_ref = LUA_NOREF; data->hkey_ref = LUA_NOREF;
DBG_PRINTF("Adding hash element\n"); DBG_PRINTF("Adding hash element\n");
} }
...@@ -124,7 +123,7 @@ create_new_element(jsonsl_t jsn, ...@@ -124,7 +123,7 @@ create_new_element(jsonsl_t jsn,
if (data->pos_ref != LUA_NOREF) { if (data->pos_ref != LUA_NOREF) {
lua_rawgeti(data->L, LUA_REGISTRYINDEX, data->metatable); lua_rawgeti(data->L, LUA_REGISTRYINDEX, data->metatable);
lua_getfield(data->L, -1, "checkpath"); lua_getfield(data->L, -1, "checkpath");
if (lua_type(data->L, -1) != LUA_TNIL) { if (!lua_isnil(data->L, -1)) {
// Call with the new table and the path as arguments // Call with the new table and the path as arguments
lua_rawgeti(data->L, LUA_REGISTRYINDEX, state->lua_object_ref); lua_rawgeti(data->L, LUA_REGISTRYINDEX, state->lua_object_ref);
lua_rawgeti(data->L, LUA_REGISTRYINDEX, data->pos_ref); lua_rawgeti(data->L, LUA_REGISTRYINDEX, data->pos_ref);
...@@ -217,7 +216,7 @@ static void push_string(JSN_DATA *data, struct jsonsl_state_st *state) { ...@@ -217,7 +216,7 @@ static void push_string(JSN_DATA *data, struct jsonsl_state_st *state) {
continue; continue;
} }
} }
luaL_putchar(&b, nc); luaL_addchar(&b, nc);
} }
luaL_pushresult(&b); luaL_pushresult(&b);
} }
...@@ -236,7 +235,7 @@ cleanup_closing_element(jsonsl_t jsn, ...@@ -236,7 +235,7 @@ cleanup_closing_element(jsonsl_t jsn,
switch (state->type) { switch (state->type) {
case JSONSL_T_HKEY: case JSONSL_T_HKEY:
push_string(data, state); push_string(data, state);
data->hkey_ref = lua_ref(data->L, 1); data->hkey_ref = luaL_ref(data->L, LUA_REGISTRYINDEX);
break; break;
case JSONSL_T_STRING: case JSONSL_T_STRING:
...@@ -247,7 +246,7 @@ cleanup_closing_element(jsonsl_t jsn, ...@@ -247,7 +246,7 @@ cleanup_closing_element(jsonsl_t jsn,
} else { } else {
// object, so // object, so
lua_rawgeti(data->L, LUA_REGISTRYINDEX, data->hkey_ref); lua_rawgeti(data->L, LUA_REGISTRYINDEX, data->hkey_ref);
lua_unref(data->L, data->hkey_ref); luaL_unref(data->L, LUA_REGISTRYINDEX, data->hkey_ref);
data->hkey_ref = LUA_NOREF; data->hkey_ref = LUA_NOREF;
} }
push_string(data, state); push_string(data, state);
...@@ -278,7 +277,7 @@ cleanup_closing_element(jsonsl_t jsn, ...@@ -278,7 +277,7 @@ cleanup_closing_element(jsonsl_t jsn,
} else { } else {
// object, so // object, so
lua_rawgeti(data->L, LUA_REGISTRYINDEX, data->hkey_ref); lua_rawgeti(data->L, LUA_REGISTRYINDEX, data->hkey_ref);
lua_unref(data->L, data->hkey_ref); luaL_unref(data->L, LUA_REGISTRYINDEX, data->hkey_ref);
data->hkey_ref = LUA_NOREF; data->hkey_ref = LUA_NOREF;
} }
lua_pushvalue(data->L, -3); lua_pushvalue(data->L, -3);
...@@ -289,7 +288,7 @@ cleanup_closing_element(jsonsl_t jsn, ...@@ -289,7 +288,7 @@ cleanup_closing_element(jsonsl_t jsn,
break; break;
case JSONSL_T_OBJECT: case JSONSL_T_OBJECT:
case JSONSL_T_LIST: case JSONSL_T_LIST:
lua_unref(data->L, state->lua_object_ref); luaL_unref(data->L, LUA_REGISTRYINDEX, state->lua_object_ref);
state->lua_object_ref = LUA_NOREF; state->lua_object_ref = LUA_NOREF;
if (data->pos_ref != LUA_NOREF) { if (data->pos_ref != LUA_NOREF) {
lua_rawgeti(data->L, LUA_REGISTRYINDEX, data->pos_ref); lua_rawgeti(data->L, LUA_REGISTRYINDEX, data->pos_ref);
...@@ -351,7 +350,7 @@ static int sjson_decoder_int(lua_State *L, int argno) { ...@@ -351,7 +350,7 @@ static int sjson_decoder_int(lua_State *L, int argno) {
data->min_needed = data->min_available = jsn->pos; data->min_needed = data->min_available = jsn->pos;
lua_pushlightuserdata(L, 0); lua_pushlightuserdata(L, 0);
data->null_ref = lua_ref(L, 1); data->null_ref = luaL_ref(L, LUA_REGISTRYINDEX);
// This may throw... // This may throw...
lua_newtable(L); lua_newtable(L);
...@@ -361,17 +360,17 @@ static int sjson_decoder_int(lua_State *L, int argno) { ...@@ -361,17 +360,17 @@ static int sjson_decoder_int(lua_State *L, int argno) {
luaL_unref(L, LUA_REGISTRYINDEX, data->null_ref); luaL_unref(L, LUA_REGISTRYINDEX, data->null_ref);
data->null_ref = LUA_NOREF; data->null_ref = LUA_NOREF;
lua_getfield(L, argno, "null"); lua_getfield(L, argno, "null");
data->null_ref = lua_ref(L, 1); data->null_ref = luaL_ref(L, LUA_REGISTRYINDEX);
lua_getfield(L, argno, "metatable"); lua_getfield(L, argno, "metatable");
lua_pushvalue(L, -1); lua_pushvalue(L, -1);
data->metatable = lua_ref(L, 1); data->metatable = luaL_ref(L, LUA_REGISTRYINDEX);
if (lua_type(L, -1) != LUA_TNIL) { if (!lua_isnil(L, -1)) {
lua_getfield(L, -1, "checkpath"); lua_getfield(L, -1, "checkpath");
if (lua_type(L, -1) != LUA_TNIL) { if (!lua_isnil(L, -1)) {
lua_newtable(L); lua_newtable(L);
data->pos_ref = lua_ref(L, 1); data->pos_ref = luaL_ref(L, LUA_REGISTRYINDEX);
} }
lua_pop(L, 1); // Throw away the checkpath value lua_pop(L, 1); // Throw away the checkpath value
} }
...@@ -477,7 +476,7 @@ static int sjson_decoder_write_int(lua_State *L, int udata_pos, int string_pos) ...@@ -477,7 +476,7 @@ static int sjson_decoder_write_int(lua_State *L, int udata_pos, int string_pos)
size_t blen; size_t blen;
data->buffer = luaL_checklstring(L, -1, &blen); data->buffer = luaL_checklstring(L, -1, &blen);
data->buffer_len = blen; data->buffer_len = blen;
data->buffer_ref = lua_ref(L, 1); data->buffer_ref = luaL_ref(L, LUA_REGISTRYINDEX);
jsonsl_feed(data->jsn, str, len); jsonsl_feed(data->jsn, str, len);
...@@ -611,9 +610,9 @@ static void enc_pop_stack(lua_State *L, ENC_DATA *data) { ...@@ -611,9 +610,9 @@ static void enc_pop_stack(lua_State *L, ENC_DATA *data) {
} }
ENC_DATA_STATE *state = &data->stack[data->level]; ENC_DATA_STATE *state = &data->stack[data->level];
lua_unref(L, state->lua_object_ref); luaL_unref(L, LUA_REGISTRYINDEX, state->lua_object_ref);
state->lua_object_ref = LUA_NOREF; state->lua_object_ref = LUA_NOREF;
lua_unref(L, state->lua_key_ref); luaL_unref(L, LUA_REGISTRYINDEX, state->lua_key_ref);
state->lua_key_ref = LUA_REFNIL; state->lua_key_ref = LUA_REFNIL;
data->level--; data->level--;
} }
...@@ -624,7 +623,7 @@ static void enc_push_stack(lua_State *L, ENC_DATA *data, int argno) { ...@@ -624,7 +623,7 @@ static void enc_push_stack(lua_State *L, ENC_DATA *data, int argno) {
} }
lua_pushvalue(L, argno); lua_pushvalue(L, argno);
ENC_DATA_STATE *state = &data->stack[data->level]; ENC_DATA_STATE *state = &data->stack[data->level];
state->lua_object_ref = lua_ref(L, 1); state->lua_object_ref = luaL_ref(L, LUA_REGISTRYINDEX);
state->size = sjson_encoder_get_table_size(L, argno); state->size = sjson_encoder_get_table_size(L, argno);
state->offset = 0; // We haven't started on this one yet state->offset = 0; // We haven't started on this one yet
} }
...@@ -674,7 +673,7 @@ static int sjson_encoder(lua_State *L) { ...@@ -674,7 +673,7 @@ static int sjson_encoder(lua_State *L) {
luaL_unref(L, LUA_REGISTRYINDEX, data->null_ref); luaL_unref(L, LUA_REGISTRYINDEX, data->null_ref);
data->null_ref = LUA_NOREF; data->null_ref = LUA_NOREF;
lua_getfield(L, argno, "null"); lua_getfield(L, argno, "null");
data->null_ref = lua_ref(L, 1); data->null_ref = luaL_ref(L, LUA_REGISTRYINDEX);
} }
return 1; return 1;
...@@ -785,10 +784,7 @@ static void encode_lua_object(lua_State *L, ENC_DATA *data, int argno, const cha ...@@ -785,10 +784,7 @@ static void encode_lua_object(lua_State *L, ENC_DATA *data, int argno, const cha
static int sjson_encoder_next_value_is_table(lua_State *L) { static int sjson_encoder_next_value_is_table(lua_State *L) {
int count = 10; int count = 10;
while ((lua_type(L, -1) == LUA_TFUNCTION while ((lua_isfunction(L, -1)
#ifdef LUA_TLIGHTFUNCTION
|| lua_type(L, -1) == LUA_TLIGHTFUNCTION
#endif
) && count-- > 0) { ) && count-- > 0) {
// call it and use the return value // call it and use the return value
lua_call(L, 0, 1); // Expecting replacement value lua_call(L, 0, 1); // Expecting replacement value
...@@ -806,7 +802,7 @@ static void sjson_encoder_make_next_chunk(lua_State *L, ENC_DATA *data) { ...@@ -806,7 +802,7 @@ static void sjson_encoder_make_next_chunk(lua_State *L, ENC_DATA *data) {
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
// Ending condition // Ending condition
while (data->level >= 0 && !b.lvl) { while (data->level >= 0 /* && !b.lvl */) {
ENC_DATA_STATE *state = &data->stack[data->level]; ENC_DATA_STATE *state = &data->stack[data->level];
int finished = 0; int finished = 0;
...@@ -849,11 +845,11 @@ static void sjson_encoder_make_next_chunk(lua_State *L, ENC_DATA *data) { ...@@ -849,11 +845,11 @@ static void sjson_encoder_make_next_chunk(lua_State *L, ENC_DATA *data) {
if (lua_next(L, -2)) { if (lua_next(L, -2)) {
// save the key // save the key
if (state->offset & 1) { if (state->offset & 1) {
lua_unref(L, state->lua_key_ref); luaL_unref(L, LUA_REGISTRYINDEX, state->lua_key_ref);
state->lua_key_ref = LUA_NOREF; state->lua_key_ref = LUA_NOREF;
// Duplicate the key // Duplicate the key
lua_pushvalue(L, -2); lua_pushvalue(L, -2);
state->lua_key_ref = lua_ref(L, 1); state->lua_key_ref = luaL_ref(L, LUA_REGISTRYINDEX);
} }
if ((state->offset & 1) == 0) { if ((state->offset & 1) == 0) {
...@@ -895,7 +891,7 @@ static void sjson_encoder_make_next_chunk(lua_State *L, ENC_DATA *data) { ...@@ -895,7 +891,7 @@ static void sjson_encoder_make_next_chunk(lua_State *L, ENC_DATA *data) {
} }
} }
luaL_pushresult(&b); luaL_pushresult(&b);
data->current_str_ref = lua_ref(L, 1); data->current_str_ref = luaL_ref(L, LUA_REGISTRYINDEX);
data->offset = 0; data->offset = 0;
} }
...@@ -923,7 +919,7 @@ static int sjson_encoder_read_int(lua_State *L, ENC_DATA *data, int readsize) { ...@@ -923,7 +919,7 @@ static int sjson_encoder_read_int(lua_State *L, ENC_DATA *data, int readsize) {
readsize -= amnt; readsize -= amnt;
if (data->offset == len) { if (data->offset == len) {
lua_unref(L, data->current_str_ref); luaL_unref(L, LUA_REGISTRYINDEX, data->current_str_ref);
data->current_str_ref = LUA_NOREF; data->current_str_ref = LUA_NOREF;
} }
} }
...@@ -992,32 +988,33 @@ static int sjson_encoder_destructor(lua_State *L) { ...@@ -992,32 +988,33 @@ static int sjson_encoder_destructor(lua_State *L) {
return 0; return 0;
} }
LROT_BEGIN(sjson_encoder)
LROT_FUNCENTRY( read, sjson_encoder_read ) LROT_BEGIN(sjson_encoder_map, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, sjson_encoder_destructor ) LROT_FUNCENTRY( __gc, sjson_encoder_destructor )
LROT_TABENTRY( __index, sjson_encoder ) LROT_TABENTRY( __index, sjson_encoder_map )
LROT_END( sjson_encoder, sjson_encoder, LROT_MASK_GC_INDEX ) LROT_FUNCENTRY( read, sjson_encoder_read )
LROT_END(sjson_encoder_map, NULL, LROT_MASK_GC_INDEX)
LROT_BEGIN(sjson_decoder)
LROT_BEGIN(sjson_decoder_map, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, sjson_decoder_destructor )
LROT_TABENTRY( __index, sjson_decoder_map )
LROT_FUNCENTRY( write, sjson_decoder_write ) LROT_FUNCENTRY( write, sjson_decoder_write )
LROT_FUNCENTRY( result, sjson_decoder_result ) LROT_FUNCENTRY( result, sjson_decoder_result )
LROT_FUNCENTRY( __gc, sjson_decoder_destructor ) LROT_END(sjson_decoder_map, NULL, LROT_MASK_GC_INDEX)
LROT_TABENTRY( __index, sjson_decoder )
LROT_END( sjson_decoder, sjson_decoder, LROT_MASK_GC_INDEX )
LROT_BEGIN(sjson) LROT_BEGIN(sjson, NULL, 0)
LROT_FUNCENTRY( encode, sjson_encode ) LROT_FUNCENTRY( encode, sjson_encode )
LROT_FUNCENTRY( decode, sjson_decode ) LROT_FUNCENTRY( decode, sjson_decode )
LROT_FUNCENTRY( encoder, sjson_encoder ) LROT_FUNCENTRY( encoder, sjson_encoder )
LROT_FUNCENTRY( decoder, sjson_decoder ) LROT_FUNCENTRY( decoder, sjson_decoder )
LROT_LUDENTRY( NULL, 0 ) LROT_END(sjson, NULL, 0)
LROT_END( sjson, NULL, 0 )
LUALIB_API int luaopen_sjson (lua_State *L) { LUALIB_API int luaopen_sjson (lua_State *L) {
luaL_rometatable(L, "sjson.decoder", LROT_TABLEREF(sjson_decoder)); luaL_rometatable(L, "sjson.decoder", LROT_TABLEREF(sjson_decoder_map));
luaL_rometatable(L, "sjson.encoder", LROT_TABLEREF(sjson_encoder)); luaL_rometatable(L, "sjson.encoder", LROT_TABLEREF(sjson_encoder_map));
return 1; return 1;
} }
......
...@@ -873,13 +873,13 @@ static int sntp_open(lua_State *L) ...@@ -873,13 +873,13 @@ static int sntp_open(lua_State *L)
// Module function map // Module function map
LROT_BEGIN(sntp) LROT_BEGIN(sntp, NULL, 0)
LROT_FUNCENTRY( sync, sntp_sync ) LROT_FUNCENTRY( sync, sntp_sync )
#ifdef LUA_USE_MODULES_RTCTIME #ifdef LUA_USE_MODULES_RTCTIME
LROT_FUNCENTRY( setoffset, sntp_setoffset ) LROT_FUNCENTRY( setoffset, sntp_setoffset )
LROT_FUNCENTRY( getoffset, sntp_getoffset ) LROT_FUNCENTRY( getoffset, sntp_getoffset )
#endif #endif
LROT_END( sntp, NULL, 0 ) LROT_END(sntp, NULL, 0)
NODEMCU_MODULE(SNTP, "sntp", sntp, sntp_open); NODEMCU_MODULE(SNTP, "sntp", sntp, sntp_open);
...@@ -334,7 +334,7 @@ static int softuart_on(lua_State *L) ...@@ -334,7 +334,7 @@ static int softuart_on(lua_State *L)
} }
if (lua_type(L, stack) == LUA_TFUNCTION || lua_type(L, stack) == LUA_TLIGHTFUNCTION) { if (lua_type(L, stack) == LUA_TFUNCTION) {
lua_pushvalue(L, stack); // Copy to top of the stack lua_pushvalue(L, stack); // Copy to top of the stack
} else { } else {
lua_pushnil(L); lua_pushnil(L);
...@@ -415,18 +415,17 @@ static int softuart_gcdelete(lua_State *L) ...@@ -415,18 +415,17 @@ static int softuart_gcdelete(lua_State *L)
} }
// Port function map // Port function map
LROT_BEGIN(softuart_port) LROT_BEGIN(softuart_port, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, softuart_gcdelete)
LROT_TABENTRY( __index, softuart_port)
LROT_FUNCENTRY( on, softuart_on) LROT_FUNCENTRY( on, softuart_on)
LROT_FUNCENTRY( write, softuart_write) LROT_FUNCENTRY( write, softuart_write)
LROT_TABENTRY( __index, softuart_port) LROT_END(softuart_port, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, softuart_gcdelete)
LROT_END(ads1115, softuart_port, LROT_MASK_GC_INDEX)
// Module function map // Module function map
LROT_BEGIN(softuart) LROT_BEGIN(softuart, LROT_TABLEREF(softuart_port), 0)
LROT_FUNCENTRY( setup, softuart_setup) LROT_FUNCENTRY( setup, softuart_setup)
LROT_TABENTRY(__metatable, softuart_port) LROT_END(softuart, LROT_TABLEREF(softuart_port), 0)
LROT_END(softuart, NULL, 0 )
static int luaopen_softuart(lua_State *L) static int luaopen_softuart(lua_State *L)
{ {
...@@ -434,7 +433,7 @@ static int luaopen_softuart(lua_State *L) ...@@ -434,7 +433,7 @@ static int luaopen_softuart(lua_State *L)
softuart_rx_cb_ref[i] = LUA_NOREF; softuart_rx_cb_ref[i] = LUA_NOREF;
} }
uart_recieve_task = task_get_id((task_callback_t) softuart_rx_callback); uart_recieve_task = task_get_id((task_callback_t) softuart_rx_callback);
luaL_rometatable(L, "softuart.port", (void *)softuart_port_map); luaL_rometatable(L, "softuart.port", LROT_TABLEREF(softuart_port));
return 0; return 0;
} }
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "lmem.h" #include "lmem.h"
#include "platform.h" #include "platform.h"
#include "task/task.h" #include "task/task.h"
#include "hw_timer.h" #include "hw_timer.h"
#include "user_interface.h" #include "user_interface.h"
...@@ -233,13 +233,13 @@ static int somfy_lua_sendcommand(lua_State* L) { // pin, remote, command, rollin ...@@ -233,13 +233,13 @@ static int somfy_lua_sendcommand(lua_State* L) { // pin, remote, command, rollin
return 0; return 0;
} }
LROT_BEGIN(somfy) LROT_BEGIN(somfy, NULL, 0)
LROT_NUMENTRY( UP, SOMFY_UP ) LROT_NUMENTRY( UP, SOMFY_UP )
LROT_NUMENTRY( DOWN, SOMFY_DOWN ) LROT_NUMENTRY( DOWN, SOMFY_DOWN )
LROT_NUMENTRY( PROG, SOMFY_PROG ) LROT_NUMENTRY( PROG, SOMFY_PROG )
LROT_NUMENTRY( STOP, SOMFY_STOP ) LROT_NUMENTRY( STOP, SOMFY_STOP )
LROT_FUNCENTRY( sendcommand, somfy_lua_sendcommand ) LROT_FUNCENTRY( sendcommand, somfy_lua_sendcommand )
LROT_END( somfy, NULL, 0 ) LROT_END(somfy, NULL, 0)
int luaopen_somfy( lua_State *L ) { int luaopen_somfy( lua_State *L ) {
......
...@@ -319,7 +319,7 @@ static int spi_set_clock_div( lua_State *L ) ...@@ -319,7 +319,7 @@ static int spi_set_clock_div( lua_State *L )
// Module function map // Module function map
LROT_BEGIN(spi) LROT_BEGIN(spi, NULL, 0)
LROT_FUNCENTRY( setup, spi_setup ) LROT_FUNCENTRY( setup, spi_setup )
LROT_FUNCENTRY( send, spi_send_recv ) LROT_FUNCENTRY( send, spi_send_recv )
LROT_FUNCENTRY( recv, spi_recv ) LROT_FUNCENTRY( recv, spi_recv )
...@@ -336,7 +336,7 @@ LROT_BEGIN(spi) ...@@ -336,7 +336,7 @@ LROT_BEGIN(spi)
LROT_NUMENTRY( DATABITS_8, 8 ) LROT_NUMENTRY( DATABITS_8, 8 )
LROT_NUMENTRY( HALFDUPLEX, SPI_HALFDUPLEX ) LROT_NUMENTRY( HALFDUPLEX, SPI_HALFDUPLEX )
LROT_NUMENTRY( FULLDUPLEX, SPI_FULLDUPLEX ) LROT_NUMENTRY( FULLDUPLEX, SPI_FULLDUPLEX )
LROT_END( spi, NULL, 0 ) LROT_END(spi, NULL, 0)
NODEMCU_MODULE(SPI, "spi", spi, NULL); NODEMCU_MODULE(SPI, "spi", spi, NULL);
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#define LUA_LIB #define LUA_LIB
#include "module.h" #include "module.h"
#include "lua.h"
#include "lauxlib.h" #include "lauxlib.h"
#if LUA_VERSION_NUM > 501 #if LUA_VERSION_NUM > 501
......
...@@ -35,8 +35,6 @@ ...@@ -35,8 +35,6 @@
#include <string.h> #include <string.h>
#include "module.h" #include "module.h"
#include "lua.h"
#include "lauxlib.h" #include "lauxlib.h"
...@@ -389,11 +387,11 @@ static int b_size (lua_State *L) { ...@@ -389,11 +387,11 @@ static int b_size (lua_State *L) {
/* }====================================================== */ /* }====================================================== */
LROT_BEGIN(thislib) LROT_BEGIN(thislib, NULL, 0)
LROT_FUNCENTRY( pack, b_pack ) LROT_FUNCENTRY( pack, b_pack )
LROT_FUNCENTRY( unpack, b_unpack ) LROT_FUNCENTRY( unpack, b_unpack )
LROT_FUNCENTRY( size, b_size ) LROT_FUNCENTRY( size, b_size )
LROT_END( thislib, NULL, 0 ) LROT_END(thislib, NULL, 0)
......
...@@ -33,7 +33,7 @@ static void callback_free(lua_State* L, unsigned int id) ...@@ -33,7 +33,7 @@ static void callback_free(lua_State* L, unsigned int id)
static void callback_set(lua_State* L, unsigned int id, int argNumber) static void callback_set(lua_State* L, unsigned int id, int argNumber)
{ {
if (lua_type(L, argNumber) == LUA_TFUNCTION || lua_type(L, argNumber) == LUA_TLIGHTFUNCTION) { if (lua_isfunction(L, argNumber)) {
lua_pushvalue(L, argNumber); // copy argument (func) to the top of stack lua_pushvalue(L, argNumber); // copy argument (func) to the top of stack
callback_free(L, id); callback_free(L, id);
stopped_callback[id] = luaL_ref(L, LUA_REGISTRYINDEX); stopped_callback[id] = luaL_ref(L, LUA_REGISTRYINDEX);
...@@ -196,7 +196,7 @@ static int switec_open(lua_State *L) ...@@ -196,7 +196,7 @@ static int switec_open(lua_State *L)
// Module function map // Module function map
LROT_BEGIN(switec) LROT_BEGIN(switec, NULL, 0)
LROT_FUNCENTRY( setup, lswitec_setup ) LROT_FUNCENTRY( setup, lswitec_setup )
LROT_FUNCENTRY( close, lswitec_close ) LROT_FUNCENTRY( close, lswitec_close )
LROT_FUNCENTRY( reset, lswitec_reset ) LROT_FUNCENTRY( reset, lswitec_reset )
...@@ -206,7 +206,7 @@ LROT_BEGIN(switec) ...@@ -206,7 +206,7 @@ LROT_BEGIN(switec)
LROT_FUNCENTRY( dequeue, lswitec_dequeue ) LROT_FUNCENTRY( dequeue, lswitec_dequeue )
#endif #endif
LROT_END( switec, NULL, 0 ) LROT_END(switec, NULL, 0)
NODEMCU_MODULE(SWITEC, "switec", switec, switec_open); NODEMCU_MODULE(SWITEC, "switec", switec, switec_open);
...@@ -100,13 +100,13 @@ typedef enum ...@@ -100,13 +100,13 @@ typedef enum
} }
tcs34725Gain_t; tcs34725Gain_t;
static void temp_setup_debug(int line, const char *str); static void temp_setup_debug(int line, const char *str);
uint8_t tcs34725Setup(lua_State* L); int tcs34725Setup(lua_State* L);
uint8_t tcs34725Enable(lua_State* L); int tcs34725Enable(lua_State* L);
uint8_t tcs34725Disable(lua_State* L); int tcs34725Disable(lua_State* L);
uint8_t tcs34725GetRawData(lua_State* L); int tcs34725GetRawData(lua_State* L);
uint8_t tcs34725LuaSetIntegrationTime(lua_State* L); int tcs34725LuaSetIntegrationTime(lua_State* L);
uint8_t tcs34725SetIntegrationTime(tcs34725IntegrationTime_t it, lua_State* L); uint8_t tcs34725SetIntegrationTime(tcs34725IntegrationTime_t it, lua_State* L);
uint8_t tcs34725LuaSetGain(lua_State* L); int tcs34725LuaSetGain(lua_State* L);
uint8_t tcs34725SetGain(tcs34725Gain_t gain, lua_State* L); uint8_t tcs34725SetGain(tcs34725Gain_t gain, lua_State* L);
static bool _tcs34725Initialised = false; static bool _tcs34725Initialised = false;
...@@ -198,11 +198,11 @@ uint8_t tcs34725EnableDone() ...@@ -198,11 +198,11 @@ uint8_t tcs34725EnableDone()
@brief Enables the device @brief Enables the device
*/ */
/**************************************************************************/ /**************************************************************************/
uint8_t tcs34725Enable(lua_State* L) int tcs34725Enable(lua_State* L)
{ {
dbg_printf("Enable begun\n"); dbg_printf("Enable begun\n");
if (lua_type(L, 1) == LUA_TFUNCTION || lua_type(L, 1) == LUA_TLIGHTFUNCTION) { if (lua_isfunction(L, 1)) {
if (cb_tcs_en != LUA_NOREF) { if (cb_tcs_en != LUA_NOREF) {
luaL_unref(L, LUA_REGISTRYINDEX, cb_tcs_en); luaL_unref(L, LUA_REGISTRYINDEX, cb_tcs_en);
} }
...@@ -226,7 +226,7 @@ uint8_t tcs34725Enable(lua_State* L) ...@@ -226,7 +226,7 @@ uint8_t tcs34725Enable(lua_State* L)
@brief Disables the device (putting it in lower power sleep mode) @brief Disables the device (putting it in lower power sleep mode)
*/ */
/**************************************************************************/ /**************************************************************************/
uint8_t tcs34725Disable(lua_State* L) int tcs34725Disable(lua_State* L)
{ {
/* Turn the device off to save power */ /* Turn the device off to save power */
uint8_t reg = 0; uint8_t reg = 0;
...@@ -241,7 +241,7 @@ uint8_t tcs34725Disable(lua_State* L) ...@@ -241,7 +241,7 @@ uint8_t tcs34725Disable(lua_State* L)
@brief Initialises the I2C block @brief Initialises the I2C block
*/ */
/**************************************************************************/ /**************************************************************************/
uint8_t tcs34725Setup(lua_State* L) int tcs34725Setup(lua_State* L)
{ {
uint8_t id = 0; uint8_t id = 0;
...@@ -261,7 +261,7 @@ uint8_t tcs34725Setup(lua_State* L) ...@@ -261,7 +261,7 @@ uint8_t tcs34725Setup(lua_State* L)
@brief Sets the integration time to the specified value @brief Sets the integration time to the specified value
*/ */
/**************************************************************************/ /**************************************************************************/
uint8_t tcs34725LuaSetIntegrationTime(lua_State* L) int tcs34725LuaSetIntegrationTime(lua_State* L)
{ {
tcs34725IntegrationTime_t it = luaL_checkinteger(L, 1); tcs34725IntegrationTime_t it = luaL_checkinteger(L, 1);
return tcs34725SetIntegrationTime(it,L); return tcs34725SetIntegrationTime(it,L);
...@@ -290,7 +290,7 @@ uint8_t tcs34725SetIntegrationTime(tcs34725IntegrationTime_t it, lua_State* L) ...@@ -290,7 +290,7 @@ uint8_t tcs34725SetIntegrationTime(tcs34725IntegrationTime_t it, lua_State* L)
@brief Sets gain to the specified value from Lua @brief Sets gain to the specified value from Lua
*/ */
/**************************************************************************/ /**************************************************************************/
uint8_t tcs34725LuaSetGain(lua_State* L) int tcs34725LuaSetGain(lua_State* L)
{ {
tcs34725Gain_t gain = luaL_checkinteger(L, 1); tcs34725Gain_t gain = luaL_checkinteger(L, 1);
return tcs34725SetGain(gain,L); return tcs34725SetGain(gain,L);
...@@ -319,7 +319,7 @@ uint8_t tcs34725SetGain(tcs34725Gain_t gain, lua_State* L) ...@@ -319,7 +319,7 @@ uint8_t tcs34725SetGain(tcs34725Gain_t gain, lua_State* L)
@brief Reads the raw red, green, blue and clear channel values @brief Reads the raw red, green, blue and clear channel values
*/ */
/**************************************************************************/ /**************************************************************************/
uint8_t tcs34725GetRawData(lua_State* L) int tcs34725GetRawData(lua_State* L)
{ {
uint16_t r; uint16_t r;
uint16_t g; uint16_t g;
...@@ -343,14 +343,14 @@ uint8_t tcs34725GetRawData(lua_State* L) ...@@ -343,14 +343,14 @@ uint8_t tcs34725GetRawData(lua_State* L)
} }
LROT_BEGIN(tcs34725) LROT_BEGIN(tcs34725, NULL, 0)
LROT_FUNCENTRY( setup, tcs34725Setup ) LROT_FUNCENTRY( setup, tcs34725Setup )
LROT_FUNCENTRY( enable, tcs34725Enable ) LROT_FUNCENTRY( enable, tcs34725Enable )
LROT_FUNCENTRY( disable, tcs34725Disable ) LROT_FUNCENTRY( disable, tcs34725Disable )
LROT_FUNCENTRY( raw, tcs34725GetRawData ) LROT_FUNCENTRY( raw, tcs34725GetRawData )
LROT_FUNCENTRY( setGain, tcs34725LuaSetGain ) LROT_FUNCENTRY( setGain, tcs34725LuaSetGain )
LROT_FUNCENTRY( setIntegrationTime, tcs34725LuaSetIntegrationTime ) LROT_FUNCENTRY( setIntegrationTime, tcs34725LuaSetIntegrationTime )
LROT_END( tcs34725, NULL, 0 ) LROT_END(tcs34725, NULL, 0)
NODEMCU_MODULE(TCS34725, "tcs34725", tcs34725, NULL); NODEMCU_MODULE(TCS34725, "tcs34725", tcs34725, NULL);
...@@ -41,7 +41,7 @@ typedef struct { ...@@ -41,7 +41,7 @@ typedef struct {
int cb_dns_ref; int cb_dns_ref;
} tls_socket_ud; } tls_socket_ud;
int tls_socket_create( lua_State *L ) { static int tls_socket_create( lua_State *L ) {
tls_socket_ud *ud = (tls_socket_ud*) lua_newuserdata(L, sizeof(tls_socket_ud)); tls_socket_ud *ud = (tls_socket_ud*) lua_newuserdata(L, sizeof(tls_socket_ud));
bzero(&ud->pesp_conn, sizeof(ud->pesp_conn)); bzero(&ud->pesp_conn, sizeof(ud->pesp_conn));
...@@ -179,12 +179,6 @@ static void tls_socket_dns_cb( const char* domain, const ip_addr_t *ip_addr, tls ...@@ -179,12 +179,6 @@ static void tls_socket_dns_cb( const char* domain, const ip_addr_t *ip_addr, tls
static int tls_socket_connect( lua_State *L ) { static int tls_socket_connect( lua_State *L ) {
tls_socket_ud *ud = (tls_socket_ud *)luaL_checkudata(L, 1, "tls.socket"); tls_socket_ud *ud = (tls_socket_ud *)luaL_checkudata(L, 1, "tls.socket");
luaL_argcheck(L, ud, 1, "TLS socket expected");
if(ud==NULL){
NODE_DBG("userdata is nil.\n");
return 0;
}
if (ud->pesp_conn.proto.tcp) { if (ud->pesp_conn.proto.tcp) {
return luaL_error(L, "already connected"); return luaL_error(L, "already connected");
} }
...@@ -231,17 +225,8 @@ static int tls_socket_connect( lua_State *L ) { ...@@ -231,17 +225,8 @@ static int tls_socket_connect( lua_State *L ) {
static int tls_socket_on( lua_State *L ) { static int tls_socket_on( lua_State *L ) {
tls_socket_ud *ud = (tls_socket_ud *)luaL_checkudata(L, 1, "tls.socket"); tls_socket_ud *ud = (tls_socket_ud *)luaL_checkudata(L, 1, "tls.socket");
luaL_argcheck(L, ud, 1, "TLS socket expected");
if(ud==NULL){
NODE_DBG("userdata is nil.\n");
return 0;
}
size_t sl; size_t sl;
const char *method = luaL_checklstring( L, 2, &sl ); const char *method = luaL_checklstring( L, 2, &sl );
if (method == NULL)
return luaL_error( L, "wrong arg type" );
int *cbp; int *cbp;
if (strcmp(method, "connection" ) == 0) { cbp = &ud->cb_connect_ref ; } if (strcmp(method, "connection" ) == 0) { cbp = &ud->cb_connect_ref ; }
...@@ -254,7 +239,7 @@ static int tls_socket_on( lua_State *L ) { ...@@ -254,7 +239,7 @@ static int tls_socket_on( lua_State *L ) {
return luaL_error(L, "invalid method"); return luaL_error(L, "invalid method");
} }
if (lua_isanyfunction(L, 3)) { if (lua_isfunction(L, 3)) {
lua_pushvalue(L, 3); // copy argument (func) to the top of stack lua_pushvalue(L, 3); // copy argument (func) to the top of stack
luaL_unref(L, LUA_REGISTRYINDEX, *cbp); luaL_unref(L, LUA_REGISTRYINDEX, *cbp);
*cbp = luaL_ref(L, LUA_REGISTRYINDEX); *cbp = luaL_ref(L, LUA_REGISTRYINDEX);
...@@ -270,35 +255,20 @@ static int tls_socket_on( lua_State *L ) { ...@@ -270,35 +255,20 @@ static int tls_socket_on( lua_State *L ) {
static int tls_socket_send( lua_State *L ) { static int tls_socket_send( lua_State *L ) {
tls_socket_ud *ud = (tls_socket_ud *)luaL_checkudata(L, 1, "tls.socket"); tls_socket_ud *ud = (tls_socket_ud *)luaL_checkudata(L, 1, "tls.socket");
luaL_argcheck(L, ud, 1, "TLS socket expected"); size_t sl;
if(ud==NULL){ const char* buf = luaL_checklstring(L, 2, &sl);
NODE_DBG("userdata is nil.\n");
return 0;
}
if(ud->pesp_conn.proto.tcp == NULL) { if(ud->pesp_conn.proto.tcp == NULL) {
NODE_DBG("not connected"); NODE_DBG("not connected");
return 0; return 0;
} }
size_t sl;
const char* buf = luaL_checklstring(L, 2, &sl);
if (!buf) {
return luaL_error(L, "wrong arg type");
}
espconn_secure_send(&ud->pesp_conn, (void*)buf, sl); espconn_secure_send(&ud->pesp_conn, (void*)buf, sl);
return 0; return 0;
} }
static int tls_socket_hold( lua_State *L ) { static int tls_socket_hold( lua_State *L ) {
tls_socket_ud *ud = (tls_socket_ud *)luaL_checkudata(L, 1, "tls.socket"); tls_socket_ud *ud = (tls_socket_ud *)luaL_checkudata(L, 1, "tls.socket");
luaL_argcheck(L, ud, 1, "TLS socket expected"); luaL_argcheck(L, ud, 1, "TLS socket expected");
if(ud==NULL){
NODE_DBG("userdata is nil.\n");
return 0;
}
if(ud->pesp_conn.proto.tcp == NULL) { if(ud->pesp_conn.proto.tcp == NULL) {
NODE_DBG("not connected"); NODE_DBG("not connected");
return 0; return 0;
...@@ -310,12 +280,6 @@ static int tls_socket_hold( lua_State *L ) { ...@@ -310,12 +280,6 @@ static int tls_socket_hold( lua_State *L ) {
} }
static int tls_socket_unhold( lua_State *L ) { static int tls_socket_unhold( lua_State *L ) {
tls_socket_ud *ud = (tls_socket_ud *)luaL_checkudata(L, 1, "tls.socket"); tls_socket_ud *ud = (tls_socket_ud *)luaL_checkudata(L, 1, "tls.socket");
luaL_argcheck(L, ud, 1, "TLS socket expected");
if(ud==NULL){
NODE_DBG("userdata is nil.\n");
return 0;
}
if(ud->pesp_conn.proto.tcp == NULL) { if(ud->pesp_conn.proto.tcp == NULL) {
NODE_DBG("not connected"); NODE_DBG("not connected");
return 0; return 0;
...@@ -328,11 +292,6 @@ static int tls_socket_unhold( lua_State *L ) { ...@@ -328,11 +292,6 @@ static int tls_socket_unhold( lua_State *L ) {
static int tls_socket_getpeer( lua_State *L ) { static int tls_socket_getpeer( lua_State *L ) {
tls_socket_ud *ud = (tls_socket_ud *)luaL_checkudata(L, 1, "tls.socket"); tls_socket_ud *ud = (tls_socket_ud *)luaL_checkudata(L, 1, "tls.socket");
luaL_argcheck(L, ud, 1, "TLS socket expected");
if(ud==NULL){
NODE_DBG("userdata is nil.\n");
return 0;
}
if(ud->pesp_conn.proto.tcp && ud->pesp_conn.proto.tcp->remote_port != 0){ if(ud->pesp_conn.proto.tcp && ud->pesp_conn.proto.tcp->remote_port != 0){
char temp[20] = {0}; char temp[20] = {0};
...@@ -345,27 +304,18 @@ static int tls_socket_getpeer( lua_State *L ) { ...@@ -345,27 +304,18 @@ static int tls_socket_getpeer( lua_State *L ) {
} }
return 2; return 2;
} }
static int tls_socket_close( lua_State *L ) { static int tls_socket_close( lua_State *L ) {
tls_socket_ud *ud = (tls_socket_ud *)luaL_checkudata(L, 1, "tls.socket"); tls_socket_ud *ud = (tls_socket_ud *)luaL_checkudata(L, 1, "tls.socket");
luaL_argcheck(L, ud, 1, "TLS socket expected");
if(ud==NULL){
NODE_DBG("userdata is nil.\n");
return 0;
}
if (ud->pesp_conn.proto.tcp) { if (ud->pesp_conn.proto.tcp) {
espconn_secure_disconnect(&ud->pesp_conn); espconn_secure_disconnect(&ud->pesp_conn);
} }
return 0; return 0;
} }
static int tls_socket_delete( lua_State *L ) { static int tls_socket_delete( lua_State *L ) {
tls_socket_ud *ud = (tls_socket_ud *)luaL_checkudata(L, 1, "tls.socket"); tls_socket_ud *ud = (tls_socket_ud *)luaL_checkudata(L, 1, "tls.socket");
luaL_argcheck(L, ud, 1, "TLS socket expected");
if(ud==NULL){
NODE_DBG("userdata is nil.\n");
return 0;
}
if (ud->pesp_conn.proto.tcp) { if (ud->pesp_conn.proto.tcp) {
espconn_secure_disconnect(&ud->pesp_conn); espconn_secure_disconnect(&ud->pesp_conn);
free(ud->pesp_conn.proto.tcp); free(ud->pesp_conn.proto.tcp);
...@@ -625,7 +575,10 @@ static int tls_set_debug_threshold(lua_State *L) { ...@@ -625,7 +575,10 @@ static int tls_set_debug_threshold(lua_State *L) {
} }
#endif #endif
LROT_BEGIN(tls_socket)
LROT_BEGIN(tls_socket, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, tls_socket_delete )
LROT_TABENTRY( __index, tls_socket )
LROT_FUNCENTRY( connect, tls_socket_connect ) LROT_FUNCENTRY( connect, tls_socket_connect )
LROT_FUNCENTRY( close, tls_socket_close ) LROT_FUNCENTRY( close, tls_socket_close )
LROT_FUNCENTRY( on, tls_socket_on ) LROT_FUNCENTRY( on, tls_socket_on )
...@@ -633,24 +586,23 @@ LROT_BEGIN(tls_socket) ...@@ -633,24 +586,23 @@ LROT_BEGIN(tls_socket)
LROT_FUNCENTRY( hold, tls_socket_hold ) LROT_FUNCENTRY( hold, tls_socket_hold )
LROT_FUNCENTRY( unhold, tls_socket_unhold ) LROT_FUNCENTRY( unhold, tls_socket_unhold )
LROT_FUNCENTRY( getpeer, tls_socket_getpeer ) LROT_FUNCENTRY( getpeer, tls_socket_getpeer )
LROT_FUNCENTRY( __gc, tls_socket_delete ) LROT_END(tls_socket, NULL, LROT_MASK_GC_INDEX)
LROT_TABENTRY( __index, tls_socket )
LROT_END( tls_socket, tls_socket, 0 )
LROT_PUBLIC_BEGIN(tls_cert) LROT_BEGIN(tls_cert, NULL, LROT_MASK_INDEX)
LROT_TABENTRY( __index, tls_cert )
LROT_FUNCENTRY( verify, tls_cert_verify ) LROT_FUNCENTRY( verify, tls_cert_verify )
LROT_FUNCENTRY( auth, tls_cert_auth ) LROT_FUNCENTRY( auth, tls_cert_auth )
LROT_END( tls_cert, tls_cert, 0 ) LROT_END(tls_cert, NULL, LROT_MASK_INDEX)
LROT_BEGIN(tls) LROT_BEGIN(tls, NULL, 0)
LROT_FUNCENTRY( createConnection, tls_socket_create ) LROT_FUNCENTRY( createConnection, tls_socket_create )
#if defined(MBEDTLS_DEBUG_C) #if defined(MBEDTLS_DEBUG_C)
LROT_FUNCENTRY( setDebug, tls_set_debug_threshold ) LROT_FUNCENTRY( setDebug, tls_set_debug_threshold )
#endif #endif
LROT_TABENTRY( cert, tls_cert ) LROT_TABENTRY( cert, tls_cert )
LROT_END( tls, tls, 0 ) LROT_END(tls, NULL, 0)
int luaopen_tls( lua_State *L ) { int luaopen_tls( lua_State *L ) {
......
...@@ -100,9 +100,9 @@ static int ICACHE_FLASH_ATTR tm1829_write(lua_State* L) ...@@ -100,9 +100,9 @@ static int ICACHE_FLASH_ATTR tm1829_write(lua_State* L)
return 0; return 0;
} }
LROT_BEGIN(tm1829) LROT_BEGIN(tm1829, NULL, 0)
LROT_FUNCENTRY( write, tm1829_write ) LROT_FUNCENTRY( write, tm1829_write )
LROT_END( tm1829, NULL, 0 ) LROT_END(tm1829, NULL, 0)
int luaopen_tm1829(lua_State *L) { int luaopen_tm1829(lua_State *L) {
......
...@@ -165,7 +165,7 @@ static int tmr_register(lua_State* L){ ...@@ -165,7 +165,7 @@ static int tmr_register(lua_State* L){
luaL_argcheck(L, (interval > 0 && interval <= MAX_TIMEOUT), 2, MAX_TIMEOUT_ERR_STR); luaL_argcheck(L, (interval > 0 && interval <= MAX_TIMEOUT), 2, MAX_TIMEOUT_ERR_STR);
luaL_argcheck(L, (mode == TIMER_MODE_SINGLE || mode == TIMER_MODE_SEMI || mode == TIMER_MODE_AUTO), 3, "Invalid mode"); luaL_argcheck(L, (mode == TIMER_MODE_SINGLE || mode == TIMER_MODE_SEMI || mode == TIMER_MODE_AUTO), 3, "Invalid mode");
luaL_argcheck(L, (lua_type(L, 4) == LUA_TFUNCTION || lua_type(L, 4) == LUA_TLIGHTFUNCTION), 4, "Must be function"); luaL_argcheck(L, lua_isfunction(L, 4), 4, "Must be function");
//get the lua function reference //get the lua function reference
lua_pushvalue(L, 4); lua_pushvalue(L, 4);
sint32_t ref = luaL_ref(L, LUA_REGISTRYINDEX); sint32_t ref = luaL_ref(L, LUA_REGISTRYINDEX);
...@@ -376,7 +376,9 @@ static int tmr_create( lua_State *L ) { ...@@ -376,7 +376,9 @@ static int tmr_create( lua_State *L ) {
// Module function map // Module function map
LROT_BEGIN(tmr_dyn) LROT_BEGIN(tmr_dyn, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, tmr_unregister )
LROT_TABENTRY( __index, tmr_dyn )
LROT_FUNCENTRY( register, tmr_register ) LROT_FUNCENTRY( register, tmr_register )
LROT_FUNCENTRY( alarm, tmr_alarm ) LROT_FUNCENTRY( alarm, tmr_alarm )
LROT_FUNCENTRY( start, tmr_start ) LROT_FUNCENTRY( start, tmr_start )
...@@ -388,12 +390,10 @@ LROT_BEGIN(tmr_dyn) ...@@ -388,12 +390,10 @@ LROT_BEGIN(tmr_dyn)
LROT_FUNCENTRY( suspend, tmr_suspend ) LROT_FUNCENTRY( suspend, tmr_suspend )
LROT_FUNCENTRY( resume, tmr_resume ) LROT_FUNCENTRY( resume, tmr_resume )
#endif #endif
LROT_FUNCENTRY( __gc, tmr_unregister ) LROT_END(tmr_dyn, NULL, LROT_MASK_GC_INDEX)
LROT_TABENTRY( __index, tmr_dyn )
LROT_END( tmr_dyn, tmr_dyn, LROT_MASK_GC_INDEX )
LROT_BEGIN(tmr) LROT_BEGIN(tmr, NULL, 0)
LROT_FUNCENTRY( delay, tmr_delay ) LROT_FUNCENTRY( delay, tmr_delay )
LROT_FUNCENTRY( now, tmr_now ) LROT_FUNCENTRY( now, tmr_now )
LROT_FUNCENTRY( wdclr, tmr_wdclr ) LROT_FUNCENTRY( wdclr, tmr_wdclr )
...@@ -408,7 +408,7 @@ LROT_BEGIN(tmr) ...@@ -408,7 +408,7 @@ LROT_BEGIN(tmr)
LROT_NUMENTRY( ALARM_SINGLE, TIMER_MODE_SINGLE ) LROT_NUMENTRY( ALARM_SINGLE, TIMER_MODE_SINGLE )
LROT_NUMENTRY( ALARM_SEMI, TIMER_MODE_SEMI ) LROT_NUMENTRY( ALARM_SEMI, TIMER_MODE_SEMI )
LROT_NUMENTRY( ALARM_AUTO, TIMER_MODE_AUTO ) LROT_NUMENTRY( ALARM_AUTO, TIMER_MODE_AUTO )
LROT_END( tmr, NULL, 0 ) LROT_END(tmr, NULL, 0)
#include "pm/swtimer.h" #include "pm/swtimer.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment