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
/*
** $Id: lzio.h,v 1.31.1.1 2017/04/19 17:20:42 roberto Exp $
** Buffered streams
** See Copyright Notice in lua.h
*/
#ifndef lzio_h
#define lzio_h
#include "lua.h"
#include "lmem.h"
#define EOZ (-1) /* end of stream */
typedef struct Zio ZIO;
#define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z))
typedef struct Mbuffer {
char *buffer;
size_t n;
size_t buffsize;
} Mbuffer;
#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
#define luaZ_buffer(buff) ((buff)->buffer)
#define luaZ_sizebuffer(buff) ((buff)->buffsize)
#define luaZ_bufflen(buff) ((buff)->n)
#define luaZ_buffremove(buff,i) ((buff)->n -= (i))
#define luaZ_resetbuffer(buff) ((buff)->n = 0)
#define luaZ_resizebuffer(L, buff, size) \
((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \
(buff)->buffsize, size), \
(buff)->buffsize = size)
#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
void *data);
LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */
/* --------- Private Part ------------------ */
struct Zio {
size_t n; /* bytes still unread */
const char *p; /* current position in buffer */
lua_Reader reader; /* reader function */
void *data; /* additional data */
lua_State *L; /* Lua state (for reader) */
};
LUAI_FUNC int luaZ_fill (ZIO *z);
#endif
......@@ -28,32 +28,30 @@ static int adc_readvdd33( lua_State* L )
static int adc_init107( lua_State *L )
{
uint8_t byte107 = luaL_checkinteger (L, 1);
uint32_t init_data[SPI_FLASH_SEC_SIZE/sizeof(uint32_t)];
partition_item_t pd_pt = {0,0,0};
uint32_t init_sector;
uint32 init_sector = flash_rom_get_sec_num () - 4;
luaL_argcheck(L, cast(uint8_t, byte107+1) < 2, 1, "Invalid mode");
system_partition_get_item(SYSTEM_PARTITION_PHY_DATA, &pd_pt);
init_sector = platform_flash_get_sector_of_address(pd_pt.addr);
// Note 32bit alignment so we can safely cast to uint32 for the flash api
char init_data[SPI_FLASH_SEC_SIZE] __attribute__((aligned(4)));
if (SPI_FLASH_RESULT_OK != flash_read (
init_sector * SPI_FLASH_SEC_SIZE,
(uint32 *)init_data, sizeof(init_data)))
if (pd_pt.size == 0 ||
platform_s_flash_read(init_data, pd_pt.addr, sizeof(init_data))==0)
return luaL_error(L, "flash read error");
// If it's already the correct value, we don't need to force it
if (init_data[107] == byte107)
{
if (cast(uint8_t *, init_data)[107] == byte107) {
lua_pushboolean (L, false);
return 1;
}
// Nope, it differs, we need to rewrite it
init_data[107] = byte107;
if (SPI_FLASH_RESULT_OK != flash_erase (init_sector))
cast(uint8_t *, init_data)[107] = byte107;
/* Only do erase if toggling 0x00 to 0xFF */
if(byte107 && platform_flash_erase_sector(init_sector) != PLATFORM_OK)
return luaL_error(L, "flash erase error");
if (SPI_FLASH_RESULT_OK != flash_write (
init_sector * SPI_FLASH_SEC_SIZE,
(uint32 *)init_data, sizeof(init_data)))
if(platform_flash_write(init_data, pd_pt.addr, sizeof(init_data))==0)
return luaL_error(L, "flash write error");
lua_pushboolean (L, true);
......@@ -61,13 +59,13 @@ static int adc_init107( lua_State *L )
}
// Module function map
LROT_BEGIN(adc)
LROT_BEGIN(adc, NULL, 0)
LROT_FUNCENTRY( read, adc_sample )
LROT_FUNCENTRY( readvdd33, adc_readvdd33 )
LROT_FUNCENTRY( force_init_mode, adc_init107 )
LROT_NUMENTRY( INIT_ADC, 0x00 )
LROT_NUMENTRY( INIT_VDD33, 0xff )
LROT_END( adc, NULL, 0 )
LROT_END(adc, NULL, 0)
NODEMCU_MODULE(ADC, "adc", adc, NULL);
......@@ -414,7 +414,7 @@ static int ads1115_lua_startread(lua_State *L) {
return 0;
}
luaL_argcheck(L, (lua_type(L, 2) == LUA_TFUNCTION || lua_type(L, 2) == LUA_TLIGHTFUNCTION), 2, "Must be function");
luaL_argcheck(L, lua_isfunction(L, 2), 2, "Must be function");
lua_pushvalue(L, 2);
ads_ctrl->timer_ref = luaL_ref(L, LUA_REGISTRYINDEX);
......@@ -531,7 +531,7 @@ static int ads1115_lua_delete(lua_State *L) {
return 0;
}
LROT_BEGIN(ads1115)
LROT_BEGIN(ads1115, NULL, 0)
LROT_FUNCENTRY( ads1115, ads1115_lua_register_1115 )
LROT_FUNCENTRY( ads1015, ads1115_lua_register_1015 )
LROT_FUNCENTRY( reset, ads1115_lua_reset )
......@@ -576,19 +576,19 @@ LROT_BEGIN(ads1115)
LROT_NUMENTRY( COMP_4CONV, ADS1115_CQUE_4CONV )
LROT_NUMENTRY( CMODE_TRAD, ADS1115_CMODE_TRAD )
LROT_NUMENTRY( CMODE_WINDOW, ADS1115_CMODE_WINDOW )
LROT_END(ads1115, NULL, 0 )
LROT_END(ads1115, NULL, 0)
LROT_BEGIN(ads1115_instance)
LROT_BEGIN(ads1115_instance, NULL, LROT_MASK_GC_INDEX)
LROT_TABENTRY( __index , ads1115_instance )
LROT_FUNCENTRY( __gc, ads1115_lua_delete )
LROT_FUNCENTRY( setting, ads1115_lua_setting )
LROT_FUNCENTRY( startread, ads1115_lua_startread )
LROT_FUNCENTRY( read, ads1115_lua_read )
#ifdef ADS1115_INCLUDE_TEST_FUNCTION
LROT_FUNCENTRY( test_volt_conversion, test_volt_conversion )
#endif
LROT_TABENTRY( __index, ads1115_instance )
LROT_FUNCENTRY( __gc, ads1115_lua_delete )
LROT_END(ads1115_instance, ads1115_instance, LROT_MASK_GC_INDEX )
LROT_END(ads1115_instance, NULL, LROT_MASK_GC_INDEX)
int luaopen_ads1115(lua_State *L) {
luaL_rometatable(L, metatable_name, LROT_TABLEREF(ads1115_instance));
......
......@@ -76,10 +76,10 @@ static int adxl345_read(lua_State* L) {
return 3;
}
LROT_BEGIN(adxl345)
LROT_BEGIN(adxl345, NULL, 0)
LROT_FUNCENTRY( read, adxl345_read )
LROT_FUNCENTRY( setup, adxl345_setup )
LROT_END( adxl345, NULL, 0 )
LROT_END(adxl345, NULL, 0)
NODEMCU_MODULE(ADXL345, "adxl345", adxl345, NULL);
......@@ -129,10 +129,10 @@ static int am2320_read(lua_State* L)
return 2;
}
LROT_BEGIN(am2320)
LROT_BEGIN(am2320, NULL, 0)
LROT_FUNCENTRY( read, am2320_read )
LROT_FUNCENTRY( setup, am2320_setup )
LROT_END( am2320, NULL, 0 )
LROT_END(am2320, NULL, 0)
NODEMCU_MODULE(AM2320, "am2320", am2320, NULL);
#include <stdlib.h>
#include <string.h>
#include "lualib.h"
#include "lauxlib.h"
#include "lrotable.h"
#include "module.h"
#include "platform.h"
#include "user_interface.h"
......@@ -101,14 +99,9 @@ static int apa102_write(lua_State* L) {
}
LROT_PUBLIC_BEGIN(apa102)
LROT_BEGIN(apa102, NULL, 0)
LROT_FUNCENTRY( write, apa102_write )
LROT_END( apa102, NULL, 0 )
LROT_END(apa102, NULL, 0)
LUALIB_API int luaopen_apa102(lua_State *L) {
LREGISTER(L, "apa102", apa102_map);
return 0;
}
NODEMCU_MODULE(APA102, "apa102", apa102, luaopen_apa102);
NODEMCU_MODULE(APA102, "apa102", apa102, NULL);
......@@ -119,7 +119,7 @@ static int bit_clear( lua_State* L )
return 1;
}
LROT_BEGIN(bit)
LROT_BEGIN(bit, NULL, 0)
LROT_FUNCENTRY( bnot, bit_bnot )
LROT_FUNCENTRY( band, bit_band )
LROT_FUNCENTRY( bor, bit_bor )
......@@ -132,7 +132,7 @@ LROT_BEGIN(bit)
LROT_FUNCENTRY( clear, bit_clear )
LROT_FUNCENTRY( isset, bit_isset )
LROT_FUNCENTRY( isclear, bit_isclear )
LROT_END( bit, NULL, 0 )
LROT_END(bit, NULL, 0)
NODEMCU_MODULE(BIT, "bit", bit, NULL);
......@@ -170,19 +170,20 @@ static int bloom_create(lua_State *L) {
return 1;
}
LROT_BEGIN(bloom_filter)
LROT_BEGIN(bloom_filter, NULL, LROT_MASK_INDEX)
LROT_TABENTRY( __index, bloom_filter )
LROT_FUNCENTRY( add, bloom_filter_add )
LROT_FUNCENTRY( check, bloom_filter_check )
LROT_FUNCENTRY( reset, bloom_filter_reset )
LROT_FUNCENTRY( info, bloom_filter_info )
LROT_TABENTRY( __index, bloom_filter )
LROT_END( bloom_filter, bloom_filter, LROT_MASK_INDEX )
LROT_END(bloom_filter, NULL, LROT_MASK_INDEX)
// Module function map
LROT_BEGIN(bloom)
LROT_BEGIN(bloom, NULL, 0)
LROT_FUNCENTRY( create, bloom_create )
LROT_END( bloom, NULL, 0 )
LROT_END(bloom, NULL, 0)
LUALIB_API int bloom_open(lua_State *L) {
......
......@@ -471,7 +471,7 @@ static int bme280_lua_dewpoint(lua_State* L) {
return 1;
}
LROT_BEGIN(bme280)
LROT_BEGIN(bme280, NULL, 0)
LROT_FUNCENTRY( setup, bme280_lua_setup )
LROT_FUNCENTRY( temp, bme280_lua_temp )
LROT_FUNCENTRY( baro, bme280_lua_baro )
......@@ -481,7 +481,7 @@ LROT_BEGIN(bme280)
LROT_FUNCENTRY( altitude, bme280_lua_altitude )
LROT_FUNCENTRY( dewpoint, bme280_lua_dewpoint )
LROT_FUNCENTRY( read, bme280_lua_read )
LROT_END( bme280, NULL, 0 )
LROT_END(bme280, NULL, 0)
NODEMCU_MODULE(BME280, "bme280", bme280, NULL);
......@@ -554,14 +554,14 @@ static int bme680_lua_dewpoint(lua_State* L) {
return 1;
}
LROT_BEGIN(bme680)
LROT_BEGIN(bme680, NULL, 0)
LROT_FUNCENTRY( setup, bme680_lua_setup )
LROT_FUNCENTRY( startreadout, bme680_lua_startreadout )
LROT_FUNCENTRY( qfe2qnh, bme680_lua_qfe2qnh )
LROT_FUNCENTRY( altitude, bme680_lua_altitude )
LROT_FUNCENTRY( dewpoint, bme680_lua_dewpoint )
LROT_FUNCENTRY( read, bme680_lua_read )
LROT_END( bme680, NULL, 0 )
LROT_END(bme680, NULL, 0)
NODEMCU_MODULE(BME680, "bme680", bme680, NULL);
......@@ -175,12 +175,12 @@ static int bmp085_lua_pressure(lua_State* L) {
return 1;
}
LROT_BEGIN(bmp085)
LROT_BEGIN(bmp085, NULL, 0)
LROT_FUNCENTRY( temperature, bmp085_lua_temperature )
LROT_FUNCENTRY( pressure, bmp085_lua_pressure )
LROT_FUNCENTRY( pressure_raw, bmp085_lua_pressure_raw )
LROT_FUNCENTRY( setup, bmp085_setup )
LROT_END( bmp085, NULL, 0 )
LROT_END(bmp085, NULL, 0)
NODEMCU_MODULE(BMP085, "bmp085", bmp085, NULL);
......@@ -556,27 +556,29 @@ static int coap_client_delete( lua_State* L )
}
// Module function map
LROT_BEGIN(coap_server)
LROT_BEGIN(coap_server, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, coap_server_delete )
LROT_TABENTRY( __index, coap_server )
LROT_FUNCENTRY( listen, coap_server_listen )
LROT_FUNCENTRY( close, coap_server_close )
LROT_FUNCENTRY( var, coap_server_var )
LROT_FUNCENTRY( func, coap_server_func )
LROT_FUNCENTRY( __gc, coap_server_delete )
LROT_TABENTRY( __index, coap_server )
LROT_END( coap_server, coap_server, 0 )
LROT_END(coap_server, NULL, LROT_MASK_GC_INDEX)
LROT_BEGIN(coap_client)
LROT_BEGIN(coap_client, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, coap_client_gcdelete )
LROT_TABENTRY( __index, coap_client )
LROT_FUNCENTRY( get, coap_client_get )
LROT_FUNCENTRY( post, coap_client_post )
LROT_FUNCENTRY( put, coap_client_put )
LROT_FUNCENTRY( delete, coap_client_delete )
LROT_FUNCENTRY( __gc, coap_client_gcdelete )
LROT_TABENTRY( __index, coap_client )
LROT_END( coap_client, coap_client, 0 )
LROT_END(coap_client, NULL, LROT_MASK_GC_INDEX)
LROT_BEGIN(coap)
LROT_BEGIN(coap, NULL, 0)
LROT_FUNCENTRY( Server, coap_createServer )
LROT_FUNCENTRY( Client, coap_createClient )
LROT_NUMENTRY( CON, COAP_TYPE_CON )
......@@ -587,8 +589,7 @@ LROT_BEGIN(coap)
LROT_NUMENTRY( OCTET_STREAM, COAP_CONTENTTYPE_APPLICATION_OCTET_STREAM )
LROT_NUMENTRY( EXI, COAP_CONTENTTYPE_APPLICATION_EXI )
LROT_NUMENTRY( JSON, COAP_CONTENTTYPE_APPLICATION_JSON )
LROT_TABENTRY( __metatable, coap )
LROT_END( coap, coap, 0 )
LROT_END(coap, NULL, 0)
int luaopen_coap( lua_State *L )
......
......@@ -234,12 +234,12 @@ static int cu_grb2hsv(lua_State *L) {
}
LROT_BEGIN(color_utils)
LROT_BEGIN(color_utils, NULL, 0)
LROT_FUNCENTRY( hsv2grb, cu_hsv2grb )
LROT_FUNCENTRY( hsv2grbw, cu_hsv2grbw )
LROT_FUNCENTRY( colorWheel, cu_color_wheel )
LROT_FUNCENTRY( grb2hsv, cu_grb2hsv )
LROT_END( color_utils, NULL, 0 )
LROT_END(color_utils, NULL, 0)
NODEMCU_MODULE(COLOR_UTILS, "color_utils", color_utils, NULL);
......@@ -87,7 +87,7 @@ static int lcron_create(lua_State *L) {
// Check arguments
char *strdesc = (char*)luaL_checkstring(L, 1);
void *newlist;
luaL_checkanyfunction(L, 2);
luaL_checktype(L, 2, LUA_TFUNCTION);
// Parse description
struct cronent_desc desc;
lcron_parsedesc(L, strdesc, &desc);
......@@ -140,14 +140,14 @@ static int lcron_schedule(lua_State *L) {
}
cronent_list = newlist;
lua_pushvalue(L, 1);
cronent_list[cronent_count++] = lua_ref(L, LUA_REGISTRYINDEX);
cronent_list[cronent_count++] = luaL_ref(L, LUA_REGISTRYINDEX);
}
return 0;
}
static int lcron_handler(lua_State *L) {
cronent_ud_t *ud = luaL_checkudata(L, 1, "cron.entry");
luaL_checkanyfunction(L, 2);
luaL_checktype(L, 2, LUA_TFUNCTION);
lua_pushvalue(L, 2);
luaL_unref(L, LUA_REGISTRYINDEX, ud->cb_ref);
ud->cb_ref = luaL_ref(L, LUA_REGISTRYINDEX);
......@@ -224,19 +224,21 @@ static void cron_handle_tmr() {
cron_handle_time(tm.tm_mon + 1, tm.tm_mday, tm.tm_wday, tm.tm_hour, tm.tm_min);
}
LROT_BEGIN(cronent)
LROT_BEGIN(cronent, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, lcron_delete )
LROT_TABENTRY( __index, cronent )
LROT_FUNCENTRY( schedule, lcron_schedule )
LROT_FUNCENTRY( handler, lcron_handler )
LROT_FUNCENTRY( unschedule, lcron_unschedule )
LROT_FUNCENTRY( __gc, lcron_delete )
LROT_TABENTRY( __index, cronent )
LROT_END( cronent, cronent, LROT_MASK_GC_INDEX )
LROT_END(cronent, NULL, LROT_MASK_GC_INDEX)
LROT_BEGIN(cron)
LROT_BEGIN(cron, NULL, 0)
LROT_FUNCENTRY( schedule, lcron_create )
LROT_FUNCENTRY( reset, lcron_reset )
LROT_END( cron, NULL, 0 )
LROT_END(cron, NULL, 0)
#include "pm/swtimer.h"
......
......@@ -49,10 +49,8 @@ static int call_encoder( lua_State* L, const char *function ) {
if (lua_gettop(L) != 1) {
luaL_error(L, "%s must have one argument", function);
}
lua_getfield(L, LUA_GLOBALSINDEX, "encoder");
if (!lua_istable(L, -1) && !lua_isrotable(L, -1)) { // also need table just in case encoder has been overloaded
luaL_error(L, "Cannot find encoder.%s", function);
}
lua_getglobal(L, "encoder");
luaL_checktype(L, -1, LUA_TTABLE);
lua_getfield(L, -1, function);
lua_insert(L, 1); //move function below the argument
lua_pop(L, 1); //and dump the encoder rotable from stack.
......@@ -372,7 +370,7 @@ static int crypto_encdec (lua_State *L, bool enc)
int status = mech->run (&op);
lua_pushlstring (L, buf, outlen); /* discarded on error but what the hell */
luaM_freearray(L, buf, outlen, char);
luaN_freearray(L, buf, outlen);
return status ? 1 : luaL_error (L, "crypto op failed");
......@@ -389,16 +387,17 @@ static int lcrypto_decrypt (lua_State *L)
}
// Hash function map
LROT_BEGIN(crypto_hash)
LROT_BEGIN(crypto_hash_map, NULL, LROT_MASK_INDEX)
LROT_TABENTRY( __index, crypto_hash_map )
LROT_FUNCENTRY( update, crypto_hash_update )
LROT_FUNCENTRY( finalize, crypto_hash_finalize )
LROT_TABENTRY( __index, crypto_hash )
LROT_END( crypto_hash, crypto_hash, LROT_MASK_INDEX )
LROT_END(crypto_hash_map, NULL, LROT_MASK_INDEX)
// Module function map
LROT_BEGIN(crypto)
LROT_BEGIN(crypto, NULL, 0)
LROT_FUNCENTRY( sha1, crypto_sha1 )
LROT_FUNCENTRY( toBase64, crypto_base64_encode )
LROT_FUNCENTRY( toHex, crypto_hex_encode )
......@@ -410,12 +409,12 @@ LROT_BEGIN(crypto)
LROT_FUNCENTRY( new_hmac, crypto_new_hmac )
LROT_FUNCENTRY( encrypt, lcrypto_encrypt )
LROT_FUNCENTRY( decrypt, lcrypto_decrypt )
LROT_END( crypto, NULL, 0 )
LROT_END(crypto, NULL, 0)
int luaopen_crypto ( lua_State *L )
{
luaL_rometatable(L, "crypto.hash", LROT_TABLEREF(crypto_hash));
luaL_rometatable(L, "crypto.hash", LROT_TABLEREF(crypto_hash_map));
return 0;
}
......
......@@ -213,7 +213,7 @@ static int dcc_lua_setup(lua_State* L) {
uint8_t pin = luaL_checkinteger(L, 1);
luaL_argcheck(L, platform_gpio_exists(pin) && pin>0, 1, "Invalid interrupt pin");
if (lua_type(L, 2) == LUA_TFUNCTION || lua_type(L, 3) == LUA_TLIGHTFUNCTION)
if (lua_type(L, 2) == LUA_TFUNCTION)
{
lua_pushvalue(L, 2);
register_lua_cb(L, &notify_cb);
......@@ -228,7 +228,7 @@ static int dcc_lua_setup(lua_State* L) {
uint8_t Flags = luaL_checkinteger(L, 5);
uint8_t OpsModeAddressBaseCV = luaL_checkinteger(L, 6);
if (lua_type(L, 7) == LUA_TFUNCTION || lua_type(L, 3) == LUA_TLIGHTFUNCTION)
if (lua_type(L, 7) == LUA_TFUNCTION)
{
lua_pushvalue(L, 7);
register_lua_cb(L, &CV_cb);
......@@ -258,7 +258,7 @@ int luaopen_dcc( lua_State *L ) {
}
// Module function map
LROT_BEGIN( dcc )
LROT_BEGIN(dcc, NULL, 0)
LROT_FUNCENTRY( setup, dcc_lua_setup )
LROT_FUNCENTRY( close, dcc_lua_close )
......@@ -285,6 +285,6 @@ LROT_BEGIN( dcc )
LROT_NUMENTRY( FLAGS_AUTO_FACTORY_DEFAULT, FLAGS_AUTO_FACTORY_DEFAULT )
LROT_NUMENTRY( FLAGS_OUTPUT_ADDRESS_MODE, FLAGS_OUTPUT_ADDRESS_MODE )
LROT_NUMENTRY( FLAGS_DCC_ACCESSORY_DECODER, FLAGS_DCC_ACCESSORY_DECODER )
LROT_END( dcc, NULL, 0 )
LROT_END(dcc, NULL, 0)
NODEMCU_MODULE(DCC, "dcc", dcc, luaopen_dcc);
......@@ -99,14 +99,14 @@ static int dht_lapi_readxx( lua_State *L )
// }
// Module function map
LROT_BEGIN(dht)
LROT_BEGIN(dht, NULL, 0)
LROT_FUNCENTRY( read, dht_lapi_read )
LROT_FUNCENTRY( read11, dht_lapi_read11 )
LROT_FUNCENTRY( readxx, dht_lapi_readxx )
LROT_NUMENTRY( OK, DHTLIB_OK )
LROT_NUMENTRY( ERROR_CHECKSUM, DHTLIB_ERROR_CHECKSUM )
LROT_NUMENTRY( ERROR_TIMEOUT, DHTLIB_ERROR_TIMEOUT )
LROT_END( dht, NULL, 0 )
LROT_END(dht, NULL, 0)
NODEMCU_MODULE(DHT, "dht", dht, NULL);
......@@ -114,7 +114,7 @@ static uint8 *fromHex ( lua_State* L, const uint8 *msg, size_t *len){
} else if (*p >= 'A' && *p <= 'F') {
b = *p++ - ('A' - 10);
} else {
luaM_freearray(L, out, *len, uint8);
luaN_freearray(L, out, *len);
luaL_error (L, "Invalid hex string");
}
if ((i&1) == 0) {
......@@ -137,7 +137,7 @@ static int do_func (lua_State *L, uint8 * (*conv_func)(lua_State *, const uint8
if (output) {
lua_pushlstring(L, output, len);
luaM_freearray(L, output, len, uint8);
luaN_freearray(L, output, len);
} else {
lua_pushstring(L, "");
}
......@@ -153,12 +153,12 @@ static int do_func (lua_State *L, uint8 * (*conv_func)(lua_State *, const uint8
DECLARE_FUNCTION(toHex);
// Module function map
LROT_BEGIN(encoder)
LROT_BEGIN(encoder, NULL, 0)
LROT_FUNCENTRY( fromBase64, encoder_fromBase64 )
LROT_FUNCENTRY( toBase64, encoder_toBase64 )
LROT_FUNCENTRY( fromHex, encoder_fromHex )
LROT_FUNCENTRY( toHex, encoder_toHex )
LROT_END( encoder, NULL, 0 )
LROT_END(encoder, NULL, 0)
NODEMCU_MODULE(ENCODER, "encoder", encoder, NULL);
......@@ -1969,11 +1969,11 @@ static int enduser_setup_stop(lua_State* L)
}
LROT_BEGIN(enduser_setup)
LROT_BEGIN(enduser_setup, NULL, 0)
LROT_FUNCENTRY( manual, enduser_setup_manual )
LROT_FUNCENTRY( start, enduser_setup_start )
LROT_FUNCENTRY( stop, enduser_setup_stop )
LROT_END( enduser_setup, NULL, 0 )
LROT_END(enduser_setup, NULL, 0)
NODEMCU_MODULE(ENDUSER_SETUP, "enduser_setup", enduser_setup, NULL);
......@@ -90,7 +90,6 @@ static int file_on(lua_State *L)
switch(lua_type(L, 2)) {
case LUA_TFUNCTION:
case LUA_TLIGHTFUNCTION:
lua_pushvalue(L, 2); // copy argument (func) to the top of stack
rtc_cb_ref = luaL_ref(L, LUA_REGISTRYINDEX);
vfs_register_rtc_cb(file_rtc_cb);
......@@ -651,7 +650,9 @@ static int file_vol_umount( lua_State *L )
}
LROT_BEGIN(file_obj)
LROT_BEGIN(file_obj, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, file_obj_free )
LROT_TABENTRY( __index, file_obj )
LROT_FUNCENTRY( close, file_close )
LROT_FUNCENTRY( read, file_read )
LROT_FUNCENTRY( readline, file_readline )
......@@ -659,32 +660,16 @@ LROT_BEGIN(file_obj)
LROT_FUNCENTRY( writeline, file_writeline )
LROT_FUNCENTRY( seek, file_seek )
LROT_FUNCENTRY( flush, file_flush )
LROT_FUNCENTRY( __gc, file_obj_free )
LROT_TABENTRY( __index, file_obj )
LROT_END( file_obj, file_obj, LROT_MASK_GC_INDEX )
LROT_END(file_obj, NULL, LROT_MASK_GC_INDEX)
LROT_BEGIN(file_vol)
LROT_FUNCENTRY( umount, file_vol_umount )
// LROT_FUNCENTRY( getfree, file_vol_getfree )
// LROT_FUNCENTRY( getlabel, file_vol_getlabel )
// LROT_FUNCENTRY( __gc, file_vol_free )
LROT_BEGIN(file_vol, NULL, LROT_MASK_INDEX)
LROT_TABENTRY( __index, file_vol )
LROT_END( file_vol, file_vol, LROT_MASK_GC_INDEX )
#ifdef BUILD_SPIFFS
#define LROT_FUNCENTRY_S(n,f) LROT_FUNCENTRY(n,f)
#else
#define LROT_FUNCENTRY_S(n,f)
#endif
#ifdef BUILD_FATFS
#define LROT_FUNCENTRY_F(n,f) LROT_FUNCENTRY(n,f)
#else
#define LROT_FUNCENTRY_F(n,f)
#endif
LROT_FUNCENTRY( umount, file_vol_umount )
LROT_END(file_vol, NULL, LROT_MASK_INDEX)
// Module function map
LROT_BEGIN(file)
LROT_BEGIN(file, NULL, 0)
LROT_FUNCENTRY( list, file_list )
LROT_FUNCENTRY( open, file_open )
LROT_FUNCENTRY( close, file_close )
......@@ -692,8 +677,10 @@ LROT_BEGIN(file)
LROT_FUNCENTRY( writeline, file_writeline )
LROT_FUNCENTRY( read, file_read )
LROT_FUNCENTRY( readline, file_readline )
LROT_FUNCENTRY_S( format, file_format )
LROT_FUNCENTRY_S( fscfg, file_fscfg )
#ifdef BUILD_SPIFFS
LROT_FUNCENTRY( format, file_format )
LROT_FUNCENTRY( fscfg, file_fscfg )
#endif
LROT_FUNCENTRY( remove, file_remove )
LROT_FUNCENTRY( seek, file_seek )
LROT_FUNCENTRY( flush, file_flush )
......@@ -704,9 +691,11 @@ LROT_BEGIN(file)
LROT_FUNCENTRY( fsinfo, file_fsinfo )
LROT_FUNCENTRY( on, file_on )
LROT_FUNCENTRY( stat, file_stat )
LROT_FUNCENTRY_F( mount, file_mount )
LROT_FUNCENTRY_F( chdir, file_chdir )
LROT_END( file, NULL, 0 )
#ifdef BUILD_FATFS
LROT_FUNCENTRY( mount, file_mount )
LROT_FUNCENTRY( chdir, file_chdir )
#endif
LROT_END(file, NULL, 0)
int luaopen_file( lua_State *L ) {
......
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