First phase of number to integer conversion (#3221)
This commit is contained in:
parent
0e02c0e5f3
commit
606f91664b
|
@ -110,7 +110,9 @@ LUALIB_API void luaL_assertfail(const char *file, int line, const char *message)
|
|||
#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
|
||||
#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
|
||||
#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
|
||||
#define luaL_checkunsigned(L,a) ((lua_Unsigned)luaL_checkinteger(L,a))
|
||||
#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
|
||||
#define luaL_optunsigned(L,a,d) ((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d)))
|
||||
#define luaL_checktable(L,n) luaL_checktype(L, (n), LUA_TTABLE)
|
||||
#define luaL_checkfunction(L,n) luaL_checktype(L, (n), LUA_TFUNCTION)
|
||||
|
||||
|
|
|
@ -105,12 +105,12 @@ typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
|
|||
|
||||
/* type of numbers in Lua */
|
||||
typedef LUA_NUMBER lua_Number;
|
||||
typedef LUA_FLOAT lua_Float;
|
||||
|
||||
|
||||
/* type for integer functions */
|
||||
typedef LUA_INTEGER lua_Integer;
|
||||
|
||||
|
||||
typedef LUAI_UINT32 lua_Unsigned;
|
||||
|
||||
/*
|
||||
** state manipulation
|
||||
|
@ -297,6 +297,9 @@ LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
|
|||
#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
|
||||
#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
|
||||
|
||||
#define lua_pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n))
|
||||
#define lua_tounsigned(L,i) ((lua_Unsigned)lua_tointeger(L,i))
|
||||
|
||||
/* error codes from cross-compiler returned by lua_dump */
|
||||
/* target integer is too small to hold a value */
|
||||
#define LUA_ERR_CC_INTOVERFLOW 101
|
||||
|
|
|
@ -546,6 +546,7 @@ extern int readline4lua(const char *prompt, char *buffer, int length);
|
|||
#define LUA_NUMBER_DOUBLE
|
||||
#define LUA_NUMBER double
|
||||
#endif
|
||||
#define LUA_FLOAT double
|
||||
|
||||
/*
|
||||
@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
|
||||
|
|
|
@ -87,6 +87,7 @@ typedef struct lua_State lua_State;
|
|||
|
||||
/* type of numbers in Lua */
|
||||
typedef LUA_NUMBER lua_Number;
|
||||
typedef LUA_FLOAT lua_Float;
|
||||
|
||||
|
||||
/* type for integer functions */
|
||||
|
|
|
@ -302,7 +302,7 @@
|
|||
#error "numeric float type not defined"
|
||||
|
||||
#endif /* } */
|
||||
|
||||
#define LUA_FLOAT LUA_NUMBER
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
@ -48,15 +48,13 @@ typedef size_t lua_UInteger;
|
|||
|
||||
#define LOGICAL_SHIFT(name, op) \
|
||||
static int bit_ ## name(lua_State *L) { \
|
||||
lua_pushinteger(L, (lua_UInteger)TOBIT(L, 1) op \
|
||||
(unsigned)luaL_checknumber(L, 2)); \
|
||||
lua_pushinteger(L, (lua_UInteger)TOBIT(L, 1) op luaL_checkunsigned(L, 2)); \
|
||||
return 1; \
|
||||
}
|
||||
|
||||
#define ARITHMETIC_SHIFT(name, op) \
|
||||
static int bit_ ## name(lua_State *L) { \
|
||||
lua_pushinteger(L, (lua_Integer)TOBIT(L, 1) op \
|
||||
(unsigned)luaL_checknumber(L, 2)); \
|
||||
lua_pushinteger(L, (lua_Integer)TOBIT(L, 1) op luaL_checkunsigned(L, 2)); \
|
||||
return 1; \
|
||||
}
|
||||
|
||||
|
@ -78,7 +76,7 @@ static int bit_bit( lua_State* L )
|
|||
// Lua: res = isset( value, position )
|
||||
static int bit_isset( lua_State* L )
|
||||
{
|
||||
lua_UInteger val = ( lua_UInteger )luaL_checkinteger( L, 1 );
|
||||
lua_UInteger val = luaL_checkunsigned( L, 1 );
|
||||
unsigned pos = ( unsigned )luaL_checkinteger( L, 2 );
|
||||
|
||||
lua_pushboolean( L, val & ( 1 << pos ) ? 1 : 0 );
|
||||
|
@ -88,7 +86,7 @@ static int bit_isset( lua_State* L )
|
|||
// Lua: res = isclear( value, position )
|
||||
static int bit_isclear( lua_State* L )
|
||||
{
|
||||
lua_UInteger val = ( lua_UInteger )luaL_checkinteger( L, 1 );
|
||||
lua_UInteger val = luaL_checkunsigned( L, 1 );
|
||||
unsigned pos = ( unsigned )luaL_checkinteger( L, 2 );
|
||||
|
||||
lua_pushboolean( L, val & ( 1 << pos ) ? 0 : 1 );
|
||||
|
@ -98,7 +96,7 @@ static int bit_isclear( lua_State* L )
|
|||
// Lua: res = set( value, pos1, pos2, ... )
|
||||
static int bit_set( lua_State* L )
|
||||
{
|
||||
lua_UInteger val = ( lua_UInteger )luaL_checkinteger( L, 1 );
|
||||
lua_UInteger val = luaL_checkunsigned( L, 1 );
|
||||
unsigned total = lua_gettop( L ), i;
|
||||
|
||||
for( i = 2; i <= total; i ++ )
|
||||
|
@ -110,7 +108,7 @@ static int bit_set( lua_State* L )
|
|||
// Lua: res = clear( value, pos1, pos2, ... )
|
||||
static int bit_clear( lua_State* L )
|
||||
{
|
||||
lua_UInteger val = ( lua_UInteger )luaL_checkinteger( L, 1 );
|
||||
lua_UInteger val = luaL_checkunsigned( L, 1 );
|
||||
unsigned total = lua_gettop( L ), i;
|
||||
|
||||
for( i = 2; i <= total; i ++ )
|
||||
|
|
|
@ -159,9 +159,9 @@ static int cu_hsv2grb(lua_State *L) {
|
|||
uint32_t tmp_color = hsv2grb(hue, sat, val);
|
||||
|
||||
// return
|
||||
lua_pushnumber(L, (tmp_color & 0x00FF0000) >> 16);
|
||||
lua_pushnumber(L, (tmp_color & 0x0000FF00) >> 8);
|
||||
lua_pushnumber(L, (tmp_color & 0x000000FF));
|
||||
lua_pushunsigned(L, (tmp_color & 0x00FF0000) >> 16);
|
||||
lua_pushunsigned(L, (tmp_color & 0x0000FF00) >> 8);
|
||||
lua_pushunsigned(L, (tmp_color & 0x000000FF));
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
@ -181,10 +181,10 @@ static int cu_hsv2grbw(lua_State *L) {
|
|||
uint32_t tmp_color = hsv2grbw(hue, sat, val);
|
||||
|
||||
// return g, r, b, w
|
||||
lua_pushnumber(L, (tmp_color & 0xFF000000) >> 24);
|
||||
lua_pushnumber(L, (tmp_color & 0x00FF0000) >> 16);
|
||||
lua_pushnumber(L, (tmp_color & 0x0000FF00) >> 8);
|
||||
lua_pushnumber(L, (tmp_color & 0x000000FF));
|
||||
lua_pushunsigned(L, (tmp_color & 0xFF000000) >> 24);
|
||||
lua_pushunsigned(L, (tmp_color & 0x00FF0000) >> 16);
|
||||
lua_pushunsigned(L, (tmp_color & 0x0000FF00) >> 8);
|
||||
lua_pushunsigned(L, (tmp_color & 0x000000FF));
|
||||
|
||||
return 4;
|
||||
}
|
||||
|
@ -203,9 +203,9 @@ static int cu_color_wheel(lua_State *L) {
|
|||
uint8_t b = (color & 0x000000FF) >> 0;
|
||||
|
||||
// return
|
||||
lua_pushnumber(L, g);
|
||||
lua_pushnumber(L, r);
|
||||
lua_pushnumber(L, b);
|
||||
lua_pushunsigned(L, g);
|
||||
lua_pushunsigned(L, r);
|
||||
lua_pushunsigned(L, b);
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
@ -226,9 +226,9 @@ static int cu_grb2hsv(lua_State *L) {
|
|||
uint8_t v = (hsv & 0x000000FF) >> 0;
|
||||
|
||||
// return
|
||||
lua_pushnumber(L, h);
|
||||
lua_pushnumber(L, s);
|
||||
lua_pushnumber(L, v);
|
||||
lua_pushunsigned(L, h);
|
||||
lua_pushunsigned(L, s);
|
||||
lua_pushunsigned(L, v);
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
|
|
@ -15,20 +15,25 @@ int platform_dht_exists( unsigned id )
|
|||
return ((id < NUM_DHT) && (id > 0));
|
||||
}
|
||||
|
||||
static void aux_read( lua_State *L )
|
||||
{
|
||||
double temp = dht_getTemperature();
|
||||
double humi = dht_getHumidity();
|
||||
int tempdec = (int)((temp - (int)temp) * 1000);
|
||||
int humidec = (int)((humi - (int)humi) * 1000);
|
||||
lua_pushnumber( L, (lua_Float) temp );
|
||||
lua_pushnumber( L, (lua_Float) humi );
|
||||
lua_pushinteger( L, tempdec );
|
||||
lua_pushinteger( L, humidec );
|
||||
}
|
||||
|
||||
// Lua: status, temp, humi, tempdec, humidec = dht.read( id )
|
||||
static int dht_lapi_read( lua_State *L )
|
||||
{
|
||||
unsigned id = luaL_checkinteger( L, 1 );
|
||||
MOD_CHECK_ID( dht, id );
|
||||
lua_pushinteger( L, dht_read_universal(id) );
|
||||
double temp = dht_getTemperature();
|
||||
double humi = dht_getHumidity();
|
||||
int tempdec = (int)((temp - (int)temp) * 1000);
|
||||
int humidec = (int)((humi - (int)humi) * 1000);
|
||||
lua_pushnumber( L, temp );
|
||||
lua_pushnumber( L, humi );
|
||||
lua_pushnumber( L, tempdec );
|
||||
lua_pushnumber( L, humidec );
|
||||
aux_read( L );
|
||||
return 5;
|
||||
}
|
||||
|
||||
|
@ -38,14 +43,7 @@ static int dht_lapi_read11( lua_State *L )
|
|||
unsigned id = luaL_checkinteger( L, 1 );
|
||||
MOD_CHECK_ID( dht, id );
|
||||
lua_pushinteger( L, dht_read11(id) );
|
||||
double temp = dht_getTemperature();
|
||||
double humi = dht_getHumidity();
|
||||
int tempdec = (int)((temp - (int)temp) * 1000);
|
||||
int humidec = (int)((humi - (int)humi) * 1000);
|
||||
lua_pushnumber( L, temp );
|
||||
lua_pushnumber( L, humi );
|
||||
lua_pushnumber( L, tempdec );
|
||||
lua_pushnumber( L, humidec );
|
||||
aux_read( L );
|
||||
return 5;
|
||||
}
|
||||
|
||||
|
@ -55,14 +53,7 @@ static int dht_lapi_readxx( lua_State *L )
|
|||
unsigned id = luaL_checkinteger( L, 1 );
|
||||
MOD_CHECK_ID( dht, id );
|
||||
lua_pushinteger( L, dht_read(id) );
|
||||
double temp = dht_getTemperature();
|
||||
double humi = dht_getHumidity();
|
||||
int tempdec = (int)((temp - (int)temp) * 1000);
|
||||
int humidec = (int)((humi - (int)humi) * 1000);
|
||||
lua_pushnumber( L, temp );
|
||||
lua_pushnumber( L, humi );
|
||||
lua_pushnumber( L, tempdec );
|
||||
lua_pushnumber( L, humidec );
|
||||
aux_read( L );
|
||||
return 5;
|
||||
}
|
||||
|
||||
|
|
|
@ -194,7 +194,7 @@ static void enduser_setup_error(int line, const char *str, int err)
|
|||
if (state != NULL && state->lua_err_cb_ref != LUA_NOREF)
|
||||
{
|
||||
lua_rawgeti (L, LUA_REGISTRYINDEX, state->lua_err_cb_ref);
|
||||
lua_pushnumber(L, err);
|
||||
lua_pushinteger(L, err);
|
||||
lua_pushfstring(L, "%d: \t%s", line, str);
|
||||
luaL_pcallx (L, 2, 0);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ static void http_callback( char * response, int http_status, char ** full_respon
|
|||
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, http_callback_registry);
|
||||
|
||||
lua_pushnumber(L, http_status);
|
||||
lua_pushinteger(L, http_status);
|
||||
if ( http_status != HTTP_STATUS_GENERIC_ERROR && response)
|
||||
{
|
||||
lua_pushlstring(L, response, (size_t)body_size);
|
||||
|
|
|
@ -30,7 +30,7 @@ static uint8 get_address(lua_State* L, uint8 i2c_address){
|
|||
{
|
||||
if( lua_isnumber(L, -1) )
|
||||
{
|
||||
temp_var = lua_tonumber(L, -1);
|
||||
temp_var = lua_tointeger(L, -1);
|
||||
if(temp_var < 2){
|
||||
temp_var = MCP4725_I2C_ADDR_A2_MASK & (temp_var << 2);
|
||||
addr_temp|=temp_var;
|
||||
|
@ -50,7 +50,7 @@ static uint8 get_address(lua_State* L, uint8 i2c_address){
|
|||
{
|
||||
if( lua_isnumber(L, -1) )
|
||||
{
|
||||
temp_var = lua_tonumber(L, -1);
|
||||
temp_var = lua_tointeger(L, -1);
|
||||
if(temp_var < 2){
|
||||
temp_var = MCP4725_I2C_ADDR_A1_MASK & (temp_var << 1);
|
||||
addr_temp|=temp_var;
|
||||
|
@ -70,7 +70,7 @@ static uint8 get_address(lua_State* L, uint8 i2c_address){
|
|||
{
|
||||
if( lua_isnumber(L, -1) )
|
||||
{
|
||||
temp_var = lua_tonumber(L, -1);
|
||||
temp_var = lua_tointeger(L, -1);
|
||||
if(temp_var<2){
|
||||
temp_var = MCP4725_I2C_ADDR_A0_MASK & (temp_var);
|
||||
addr_temp|=temp_var;
|
||||
|
@ -103,7 +103,7 @@ static int mcp4725_write(lua_State* L){
|
|||
{
|
||||
if( lua_isnumber(L, -1) )
|
||||
{
|
||||
temp_var = lua_tonumber(L, -1);
|
||||
temp_var = lua_tointeger(L, -1);
|
||||
if(temp_var >= 0 && temp_var<=4095){
|
||||
dac_value = temp_var<<4;
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ static int mcp4725_write(lua_State* L){
|
|||
{
|
||||
if( lua_isnumber(L, -1) )
|
||||
{
|
||||
temp_var = lua_tonumber(L, -1);
|
||||
temp_var = lua_tointeger(L, -1);
|
||||
if(temp_var >= 0 && temp_var <= 3){
|
||||
cmd_byte |= temp_var << 1;
|
||||
}
|
||||
|
@ -193,12 +193,12 @@ static int mcp4725_read(lua_State* L){
|
|||
}
|
||||
platform_i2c_send_stop(mcp4725_i2c_id);
|
||||
|
||||
lua_pushnumber(L, (recieve_buffer[0] & 0x06)>>1);
|
||||
lua_pushnumber(L, (recieve_buffer[1] << 4) | (recieve_buffer[2] >> 4));
|
||||
lua_pushnumber(L, (recieve_buffer[3] & 0x60) >> 5);
|
||||
lua_pushnumber(L, ((recieve_buffer[3] & 0xf) << 8) | recieve_buffer[4]);
|
||||
lua_pushnumber(L, (recieve_buffer[0] & 0x80) >> 7);
|
||||
lua_pushnumber(L, (recieve_buffer[0] & 0x40) >> 6);
|
||||
lua_pushinteger(L, (recieve_buffer[0] & 0x06)>>1);
|
||||
lua_pushinteger(L, (recieve_buffer[1] << 4) | (recieve_buffer[2] >> 4));
|
||||
lua_pushinteger(L, (recieve_buffer[3] & 0x60) >> 5);
|
||||
lua_pushinteger(L, ((recieve_buffer[3] & 0xf) << 8) | recieve_buffer[4]);
|
||||
lua_pushinteger(L, (recieve_buffer[0] & 0x80) >> 7);
|
||||
lua_pushinteger(L, (recieve_buffer[0] & 0x40) >> 6);
|
||||
|
||||
return 6;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ static int mdns_register(lua_State *L)
|
|||
const char *key = luaL_checkstring(L, -2);
|
||||
|
||||
if (strcmp(key, "port") == 0) {
|
||||
info.service_port = luaL_checknumber(L, -1);
|
||||
info.service_port = luaL_checkinteger(L, -1);
|
||||
} else if (strcmp(key, "service") == 0) {
|
||||
info.service_name = luaL_checkstring(L, -1);
|
||||
} else if (strcmp(key, "description") == 0) {
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
|
||||
#define DELAY2SEC 2000
|
||||
|
||||
#ifndef LUA_MAXINTEGER
|
||||
#define LUA_MAXINTEGER INT_MAX
|
||||
#endif
|
||||
|
||||
static void restart_callback(void *arg) {
|
||||
UNUSED(arg);
|
||||
system_restart();
|
||||
|
@ -67,7 +71,8 @@ static int node_restart( lua_State* L )
|
|||
}
|
||||
|
||||
static int dsleepMax( lua_State *L ) {
|
||||
lua_pushnumber(L, (uint64_t)system_rtc_clock_cali_proc()*(0x80000000-1)/(0x1000));
|
||||
uint64_t dsm = (((uint64_t)system_rtc_clock_cali_proc())*(0x80000000-1))/0x1000;
|
||||
lua_pushnumber(L, (lua_Float) dsm);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -76,34 +81,28 @@ static int node_deepsleep( lua_State* L )
|
|||
{
|
||||
uint64 us;
|
||||
uint8 option;
|
||||
//us = luaL_checkinteger( L, 1 );
|
||||
// Set deleep option, skip if nil
|
||||
if ( lua_isnumber(L, 2) )
|
||||
{
|
||||
option = lua_tointeger(L, 2);
|
||||
if ( option < 0 || option > 4)
|
||||
return luaL_error( L, "wrong arg range" );
|
||||
else
|
||||
system_deep_sleep_set_option( option );
|
||||
option = lua_tounsigned(L, 2);
|
||||
luaL_argcheck(L, 2, option <= 4, "wrong option value" );
|
||||
system_deep_sleep_set_option( option );
|
||||
}
|
||||
bool instant = false;
|
||||
if (lua_isnumber(L, 3))
|
||||
instant = lua_tointeger(L, 3);
|
||||
// Set deleep time, skip if nil
|
||||
bool instant = (lua_isnumber(L, 3) && luaL_checkinteger(L, 3)) ? true: false;
|
||||
|
||||
if ( lua_isnumber(L, 1) )
|
||||
{
|
||||
#if LUA_VERSION_NUM == 501
|
||||
us = luaL_checknumber(L, 1);
|
||||
// if ( us <= 0 )
|
||||
if ( us < 0 )
|
||||
return luaL_error( L, "wrong arg range" );
|
||||
#else /* 503 */
|
||||
us = lua_isinteger(L, 1) ? lua_tounsigned(L, 1) : (uint64) lua_tonumber(L, 1);
|
||||
#endif
|
||||
luaL_argcheck(L, 1, us < 36000000000ull, "invalid time value" );
|
||||
if (instant)
|
||||
system_deep_sleep_instant(us);
|
||||
else
|
||||
{
|
||||
if (instant)
|
||||
system_deep_sleep_instant(us);
|
||||
else
|
||||
system_deep_sleep( us );
|
||||
}
|
||||
}
|
||||
system_deep_sleep(us);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -201,7 +200,7 @@ static int node_info( lua_State* L ){
|
|||
lua_createtable(L, 0, 4);
|
||||
lua_pushboolean(L, BUILDINFO_SSL);
|
||||
lua_setfield(L, -2, "ssl");
|
||||
lua_pushnumber(L, BUILDINFO_LFS_SIZE);
|
||||
lua_pushinteger(L, BUILDINFO_LFS_SIZE);
|
||||
lua_setfield(L, -2, "lfs_size");
|
||||
add_string_field(L, BUILDINFO_MODULES, "modules");
|
||||
add_string_field(L, BUILDINFO_BUILD_TYPE, "number_type");
|
||||
|
@ -545,16 +544,25 @@ static int node_osprint( lua_State* L )
|
|||
return 0;
|
||||
}
|
||||
|
||||
int node_random_range(int l, int u) {
|
||||
static lua_Unsigned random_value() {
|
||||
// Hopefully the compiler is smart enought to spot the constant IF check
|
||||
if (sizeof(lua_Unsigned) == 4) {
|
||||
return os_random();
|
||||
} else {
|
||||
return (((uint64_t) os_random()) << 32) + (uint32_t) os_random();
|
||||
}
|
||||
}
|
||||
|
||||
lua_Integer node_random_range(lua_Integer l, lua_Integer u) {
|
||||
// The range is the number of different values to return
|
||||
unsigned int range = u + 1 - l;
|
||||
lua_Unsigned range = u + 1 - l;
|
||||
|
||||
// If this is very large then use simpler code
|
||||
if (range >= 0x7fffffff) {
|
||||
unsigned int v;
|
||||
if (range >= LUA_MAXINTEGER) {
|
||||
uint64_t v;
|
||||
|
||||
// This cannot loop more than half the time
|
||||
while ((v = os_random()) >= range) {
|
||||
while ((v = random_value()) >= range) {
|
||||
}
|
||||
|
||||
// Now v is in the range [0, range)
|
||||
|
@ -566,19 +574,19 @@ int node_random_range(int l, int u) {
|
|||
return l;
|
||||
}
|
||||
|
||||
// Another easy case -- uniform 32-bit
|
||||
// Another easy case -- uniform 32/64-bit
|
||||
if (range == 0) {
|
||||
return os_random();
|
||||
return random_value();
|
||||
}
|
||||
|
||||
// Now we have to figure out what a large multiple of range is
|
||||
// that just fits into 32 bits.
|
||||
// that just fits into 32/64 bits.
|
||||
// The limit will be less than 1 << 32 by some amount (not much)
|
||||
uint32_t limit = ((0x80000000 / ((range + 1) >> 1)) - 1) * range;
|
||||
lua_Unsigned limit = (((1 + (lua_Unsigned) LUA_MAXINTEGER) / ((range + 1) >> 1)) - 1) * range;
|
||||
|
||||
uint32_t v;
|
||||
lua_Unsigned v;
|
||||
|
||||
while ((v = os_random()) >= limit) {
|
||||
while ((v = random_value()) >= limit) {
|
||||
}
|
||||
|
||||
// Now v is uniformly distributed in [0, limit) and limit is a multiple of range
|
||||
|
@ -587,33 +595,33 @@ int node_random_range(int l, int u) {
|
|||
}
|
||||
|
||||
static int node_random (lua_State *L) {
|
||||
int u;
|
||||
int l;
|
||||
lua_Integer u;
|
||||
lua_Integer l;
|
||||
|
||||
switch (lua_gettop(L)) { /* check number of arguments */
|
||||
case 0: { /* no arguments */
|
||||
#ifdef LUA_NUMBER_INTEGRAL
|
||||
lua_pushnumber(L, 0); /* Number between 0 and 1 - always 0 with ints */
|
||||
lua_pushinteger(L, 0); /* Number between 0 and 1 - always 0 with ints */
|
||||
#else
|
||||
lua_pushnumber(L, (lua_Number)os_random() / (lua_Number)(1LL << 32));
|
||||
lua_pushnumber(L, ((double)random_value() / 16 / (1LL << (8 * sizeof(lua_Unsigned) - 4))));
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
case 1: { /* only upper limit */
|
||||
l = 1;
|
||||
u = luaL_checkint(L, 1);
|
||||
u = luaL_checkinteger(L, 1);
|
||||
break;
|
||||
}
|
||||
case 2: { /* lower and upper limits */
|
||||
l = luaL_checkint(L, 1);
|
||||
u = luaL_checkint(L, 2);
|
||||
l = luaL_checkinteger(L, 1);
|
||||
u = luaL_checkinteger(L, 2);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return luaL_error(L, "wrong number of arguments");
|
||||
}
|
||||
luaL_argcheck(L, l<=u, 2, "interval is empty");
|
||||
lua_pushnumber(L, node_random_range(l, u)); /* int between `l' and `u' */
|
||||
lua_pushinteger(L, node_random_range(l, u)); /* int between `l' and `u' */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -115,20 +115,20 @@ static int perf_stop(lua_State *L)
|
|||
DATA *d = data;
|
||||
data = NULL;
|
||||
|
||||
lua_pushnumber(L, d->total_samples);
|
||||
lua_pushnumber(L, d->outside_samples);
|
||||
lua_pushunsigned(L, d->total_samples);
|
||||
lua_pushunsigned(L, d->outside_samples);
|
||||
lua_newtable(L);
|
||||
int i;
|
||||
uint32_t addr = d->start;
|
||||
for (i = 0; i < d->bucket_count; i++, addr += (1 << d->bucket_shift)) {
|
||||
if (d->bucket[i]) {
|
||||
lua_pushnumber(L, addr);
|
||||
lua_pushnumber(L, d->bucket[i]);
|
||||
lua_pushunsigned(L, addr);
|
||||
lua_pushunsigned(L, d->bucket[i]);
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
}
|
||||
|
||||
lua_pushnumber(L, 1 << d->bucket_shift);
|
||||
lua_pushunsigned(L, 1 << d->bucket_shift);
|
||||
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, d->ref);
|
||||
|
||||
|
|
|
@ -254,8 +254,8 @@ static int lrotary_getpos( lua_State* L )
|
|||
return 0;
|
||||
}
|
||||
|
||||
lua_pushnumber(L, (pos << 1) >> 1);
|
||||
lua_pushnumber(L, (pos & 0x80000000) ? MASK(PRESS) : MASK(RELEASE));
|
||||
lua_pushinteger(L, (pos << 1) >> 1);
|
||||
lua_pushinteger(L, (pos & 0x80000000) ? MASK(PRESS) : MASK(RELEASE));
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
|
|
@ -20,22 +20,22 @@ static int rtcfifo_prepare (lua_State *L)
|
|||
#ifdef LUA_USE_MODULES_RTCTIME
|
||||
lua_getfield (L, 1, "interval_us");
|
||||
if (lua_isnumber (L, -1))
|
||||
interval_us = lua_tonumber (L, -1);
|
||||
interval_us = lua_tointeger (L, -1);
|
||||
lua_pop (L, 1);
|
||||
#endif
|
||||
|
||||
lua_getfield (L, 1, "sensor_count");
|
||||
if (lua_isnumber (L, -1))
|
||||
sensor_count = lua_tonumber (L, -1);
|
||||
sensor_count = lua_tointeger (L, -1);
|
||||
lua_pop (L, 1);
|
||||
|
||||
lua_getfield (L, 1, "storage_begin");
|
||||
if (lua_isnumber (L, -1))
|
||||
first = lua_tonumber (L, -1);
|
||||
first = lua_tointeger (L, -1);
|
||||
lua_pop (L, 1);
|
||||
lua_getfield (L, 1, "storage_end");
|
||||
if (lua_isnumber (L, -1))
|
||||
last = lua_tonumber (L, -1);
|
||||
last = lua_tointeger (L, -1);
|
||||
lua_pop (L, 1);
|
||||
}
|
||||
else if (!lua_isnone (L, 1))
|
||||
|
@ -53,7 +53,7 @@ static int rtcfifo_prepare (lua_State *L)
|
|||
// ready = rtcfifo.ready ()
|
||||
static int rtcfifo_ready (lua_State *L)
|
||||
{
|
||||
lua_pushnumber (L, rtc_fifo_check_magic ());
|
||||
lua_pushinteger (L, rtc_fifo_check_magic ());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -70,9 +70,9 @@ static int rtcfifo_put (lua_State *L)
|
|||
check_fifo_magic (L);
|
||||
|
||||
sample_t s;
|
||||
s.timestamp = luaL_checknumber (L, 1);
|
||||
s.value = luaL_checknumber (L, 2);
|
||||
s.decimals = luaL_checknumber (L, 3);
|
||||
s.timestamp = luaL_checkinteger (L, 1);
|
||||
s.value = luaL_checkinteger (L, 2);
|
||||
s.decimals = luaL_checkinteger (L, 3);
|
||||
size_t len;
|
||||
const char *str = luaL_checklstring (L, 4, &len);
|
||||
union {
|
||||
|
@ -89,9 +89,9 @@ static int rtcfifo_put (lua_State *L)
|
|||
|
||||
static int extract_sample (lua_State *L, const sample_t *s)
|
||||
{
|
||||
lua_pushnumber (L, s->timestamp);
|
||||
lua_pushnumber (L, s->value);
|
||||
lua_pushnumber (L, s->decimals);
|
||||
lua_pushinteger (L, s->timestamp);
|
||||
lua_pushinteger (L, s->value);
|
||||
lua_pushinteger (L, s->decimals);
|
||||
union {
|
||||
uint32_t u;
|
||||
char s[4];
|
||||
|
@ -125,7 +125,7 @@ static int rtcfifo_peek (lua_State *L)
|
|||
sample_t s;
|
||||
uint32_t offs = 0;
|
||||
if (lua_isnumber (L, 1))
|
||||
offs = lua_tonumber (L, 1);
|
||||
offs = lua_tointeger (L, 1);
|
||||
if (!rtc_fifo_peek_sample (&s, offs))
|
||||
return 0;
|
||||
else
|
||||
|
@ -138,7 +138,7 @@ static int rtcfifo_drop (lua_State *L)
|
|||
{
|
||||
check_fifo_magic (L);
|
||||
|
||||
rtc_fifo_drop_samples (luaL_checknumber (L, 1));
|
||||
rtc_fifo_drop_samples (luaL_checkinteger (L, 1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ static int rtcfifo_count (lua_State *L)
|
|||
{
|
||||
check_fifo_magic (L);
|
||||
|
||||
lua_pushnumber (L, rtc_fifo_get_count ());
|
||||
lua_pushinteger (L, rtc_fifo_get_count ());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ static int rtcfifo_dsleep_until_sample (lua_State *L)
|
|||
{
|
||||
check_fifo_magic (L);
|
||||
|
||||
uint32_t min_us = luaL_checknumber (L, 1);
|
||||
uint32_t min_us = luaL_checkinteger (L, 1);
|
||||
rtc_fifo_deep_sleep_until_sample (min_us); // no return
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -6,13 +6,11 @@
|
|||
|
||||
static int rtcmem_read32 (lua_State *L)
|
||||
{
|
||||
int idx = luaL_checknumber (L, 1);
|
||||
int n = 1;
|
||||
if (lua_isnumber (L, 2))
|
||||
n = lua_tonumber (L, 2);
|
||||
|
||||
if (!lua_checkstack (L, n))
|
||||
return 0;
|
||||
int idx = luaL_checkinteger (L, 1);
|
||||
int n = (lua_gettop(L) < 2) ? 1 : lua_tointeger (L, 2);
|
||||
if (n == 0 || !lua_checkstack (L, n)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
while (n > 0 && idx >= 0 && idx < RTC_USER_MEM_NUM_DWORDS)
|
||||
|
@ -27,14 +25,14 @@ static int rtcmem_read32 (lua_State *L)
|
|||
|
||||
static int rtcmem_write32 (lua_State *L)
|
||||
{
|
||||
int idx = luaL_checknumber (L, 1);
|
||||
int idx = luaL_checkinteger (L, 1);
|
||||
int n = lua_gettop (L) - 1;
|
||||
luaL_argcheck (
|
||||
L, idx + n <= RTC_USER_MEM_NUM_DWORDS, 1, "RTC mem would overrun");
|
||||
int src = 2;
|
||||
while (n-- > 0)
|
||||
{
|
||||
rtc_mem_write (idx++, lua_tonumber (L, src++));
|
||||
rtc_mem_write (idx++, (uint32_t) lua_tointeger (L, src++));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -183,13 +183,13 @@ static int si7021_lua_read(lua_State* L) {
|
|||
read_reg(SI7021_CMD_MEASURE_RH_HOLD, buf_h, 3);
|
||||
if (buf_h[2] != si7021_crc8(0, buf_h, 2)) //crc check
|
||||
return luaL_error(L, "crc error");
|
||||
double hum = (uint16_t)((buf_h[0] << 8) | buf_h[1]);
|
||||
lua_Float hum = (uint16_t)((buf_h[0] << 8) | buf_h[1]);
|
||||
hum = ((hum * 125) / 65536 - 6);
|
||||
int humdec = (int)((hum - (int)hum) * 1000);
|
||||
|
||||
uint8_t buf_t[2]; // two byte data, no crc on combined temp measurement
|
||||
read_reg(SI7021_CMD_READ_PREV_TEMP, buf_t, 2);
|
||||
double temp = (uint16_t)((buf_t[0] << 8) | buf_t[1]);
|
||||
lua_Float temp = (uint16_t)((buf_t[0] << 8) | buf_t[1]);
|
||||
temp = ((temp * 175.72) / 65536 - 46.85);
|
||||
int tempdec = (int)((temp - (int)temp) * 1000);
|
||||
|
||||
|
|
|
@ -152,21 +152,16 @@ create_new_element(jsonsl_t jsn,
|
|||
}
|
||||
|
||||
static void push_number(JSN_DATA *data, struct jsonsl_state_st *state) {
|
||||
const char *start = get_state_buffer(data, state);
|
||||
const char *end = start + state->pos_cur - state->pos_begin;
|
||||
lua_pushlstring(data->L, start, end - start);
|
||||
#if LUA_VERSION_NUM >= 503
|
||||
int sz = lua_stringtonumber(data->L, lua_tostring(data->L, -1));
|
||||
if (sz) {
|
||||
lua_pop(data->L, 1);
|
||||
} else {
|
||||
lua_pushlstring(data->L, get_state_buffer(data, state), state->pos_cur - state->pos_begin);
|
||||
#if LUA_VERSION_NUM == 501
|
||||
lua_pushnumber(data->L, lua_tonumber(data->L, -1));
|
||||
#else
|
||||
if (!lua_stringtonumber(data->L, lua_tostring(data->L, -1))) {
|
||||
// In this case stringtonumber does not push a value
|
||||
luaL_error(data->L, "Invalid number");
|
||||
}
|
||||
#else
|
||||
lua_Number result = lua_tonumber(data->L, -1);
|
||||
lua_pop(data->L, 1);
|
||||
lua_pushnumber(data->L, result);
|
||||
#endif
|
||||
lua_remove(data->L, -2);
|
||||
}
|
||||
|
||||
static int fromhex(char c) {
|
||||
|
|
|
@ -272,16 +272,16 @@ static void sntp_handle_result(lua_State *L) {
|
|||
{
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, state->sync_cb_ref);
|
||||
#ifdef LUA_USE_MODULES_RTCTIME
|
||||
lua_pushnumber(L, tv.tv_sec);
|
||||
lua_pushnumber(L, tv.tv_usec);
|
||||
lua_pushinteger(L, tv.tv_sec);
|
||||
lua_pushinteger(L, tv.tv_usec);
|
||||
lua_pushstring(L, ipaddr_ntoa (&state->best.server));
|
||||
lua_newtable(L);
|
||||
int d40 = state->best.delta >> 40;
|
||||
if (d40 != 0 && d40 != -1) {
|
||||
lua_pushnumber(L, state->best.delta >> 32);
|
||||
lua_pushinteger(L, state->best.delta >> 32);
|
||||
lua_setfield(L, -2, "offset_s");
|
||||
} else {
|
||||
lua_pushnumber(L, (state->best.delta * MICROSECONDS) >> 32);
|
||||
lua_pushinteger(L, (state->best.delta * MICROSECONDS) >> 32);
|
||||
lua_setfield(L, -2, "offset_us");
|
||||
}
|
||||
#else
|
||||
|
@ -292,26 +292,26 @@ static void sntp_handle_result(lua_State *L) {
|
|||
tv_usec -= 1000000;
|
||||
tv_sec++;
|
||||
}
|
||||
lua_pushnumber(L, tv_sec);
|
||||
lua_pushnumber(L, tv_usec);
|
||||
lua_pushinteger(L, tv_sec);
|
||||
lua_pushinteger(L, tv_usec);
|
||||
lua_pushstring(L, ipaddr_ntoa (&state->best.server));
|
||||
lua_newtable(L);
|
||||
#endif
|
||||
if (state->best.delay_frac > 0) {
|
||||
lua_pushnumber(L, FRAC16_TO_US(state->best.delay_frac));
|
||||
lua_pushinteger(L, FRAC16_TO_US(state->best.delay_frac));
|
||||
lua_setfield(L, -2, "delay_us");
|
||||
}
|
||||
lua_pushnumber(L, FRAC16_TO_US(state->best.root_delay));
|
||||
lua_pushinteger(L, FRAC16_TO_US(state->best.root_delay));
|
||||
lua_setfield(L, -2, "root_delay_us");
|
||||
lua_pushnumber(L, FRAC16_TO_US(state->best.root_dispersion));
|
||||
lua_pushinteger(L, FRAC16_TO_US(state->best.root_dispersion));
|
||||
lua_setfield(L, -2, "root_dispersion_us");
|
||||
lua_pushnumber(L, FRAC16_TO_US(state->best.root_maxerr + state->best.delay_frac / 2));
|
||||
lua_pushinteger(L, FRAC16_TO_US(state->best.root_maxerr + state->best.delay_frac / 2));
|
||||
lua_setfield(L, -2, "root_maxerr_us");
|
||||
lua_pushnumber(L, state->best.stratum);
|
||||
lua_pushinteger(L, state->best.stratum);
|
||||
lua_setfield(L, -2, "stratum");
|
||||
lua_pushnumber(L, state->best.LI);
|
||||
lua_pushinteger(L, state->best.LI);
|
||||
lua_setfield(L, -2, "leap");
|
||||
lua_pushnumber(L, pending_LI);
|
||||
lua_pushinteger(L, pending_LI);
|
||||
lua_setfield(L, -2, "pending_leap");
|
||||
}
|
||||
|
||||
|
@ -617,7 +617,7 @@ static int sntp_setoffset(lua_State *L)
|
|||
static int sntp_getoffset(lua_State *L)
|
||||
{
|
||||
update_offset();
|
||||
lua_pushnumber(L, the_offset);
|
||||
lua_pushinteger(L, the_offset);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -799,7 +799,7 @@ static int sntp_sync (lua_State *L)
|
|||
|
||||
/* Construct a singleton table containing the one server */
|
||||
lua_newtable(L);
|
||||
lua_pushnumber(L, 1);
|
||||
lua_pushinteger(L, 1);
|
||||
lua_pushstring(L, hostname);
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
|
@ -808,14 +808,14 @@ static int sntp_sync (lua_State *L)
|
|||
struct netif *iface = (struct netif *)eagle_lwip_getif(0x00);
|
||||
if (iface->dhcp && iface->dhcp->offered_ntp_addr.addr) {
|
||||
ip_addr_t ntp_addr = iface->dhcp->offered_ntp_addr;
|
||||
lua_pushnumber(L, 1);
|
||||
lua_pushinteger(L, 1);
|
||||
lua_pushstring(L, inet_ntoa(ntp_addr));
|
||||
lua_settable(L, -3);
|
||||
} else {
|
||||
// default to ntp pool
|
||||
int i;
|
||||
for (i = 0; i < 4; i++) {
|
||||
lua_pushnumber(L, i + 1);
|
||||
lua_pushinteger(L, i + 1);
|
||||
char buf[64];
|
||||
sprintf(buf, "%d.nodemcu.pool.ntp.org", i);
|
||||
lua_pushstring(L, buf);
|
||||
|
|
|
@ -152,8 +152,8 @@ static int lswitec_getpos( lua_State* L )
|
|||
if (switec_getpos( id, &pos, &dir, &target )) {
|
||||
return luaL_error( L, "Unable to get position." );
|
||||
}
|
||||
lua_pushnumber(L, pos);
|
||||
lua_pushnumber(L, dir);
|
||||
lua_pushinteger(L, pos);
|
||||
lua_pushinteger(L, dir);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ static int ICACHE_FLASH_ATTR tsl2561_init(lua_State* L) {
|
|||
tsl2561SetPackage(package);
|
||||
}
|
||||
}
|
||||
lua_pushnumber(L, error);
|
||||
lua_pushinteger(L, error);
|
||||
return 1;
|
||||
}
|
||||
/* Sets the integration time and gain settings of the device
|
||||
|
@ -71,7 +71,7 @@ static int ICACHE_FLASH_ATTR tsl2561_lua_settiming(lua_State* L) {
|
|||
return luaL_error(L, "Invalid argument: gain");
|
||||
}
|
||||
|
||||
lua_pushnumber(L, tsl2561SetTiming(integration, gain));
|
||||
lua_pushinteger(L, tsl2561SetTiming(integration, gain));
|
||||
return 1;
|
||||
}
|
||||
/* Reads sensor values from device and return calculated lux
|
||||
|
@ -80,11 +80,11 @@ static int ICACHE_FLASH_ATTR tsl2561_lua_settiming(lua_State* L) {
|
|||
static int ICACHE_FLASH_ATTR tsl2561_lua_calclux(lua_State* L) {
|
||||
uint8_t error = tsl2561GetLuminosity(&ch0, &ch1);
|
||||
if (error) {
|
||||
lua_pushnumber(L, 0);
|
||||
lua_pushnumber(L, error);
|
||||
lua_pushinteger(L, 0);
|
||||
lua_pushinteger(L, error);
|
||||
} else {
|
||||
lua_pushnumber(L, tsl2561CalculateLux(ch0, ch1));
|
||||
lua_pushnumber(L, error);
|
||||
lua_pushinteger(L, tsl2561CalculateLux(ch0, ch1));
|
||||
lua_pushinteger(L, error);
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
@ -93,9 +93,9 @@ static int ICACHE_FLASH_ATTR tsl2561_lua_calclux(lua_State* L) {
|
|||
*/
|
||||
static int ICACHE_FLASH_ATTR tsl2561_lua_getchannels(lua_State* L) {
|
||||
uint8_t error = tsl2561GetLuminosity(&ch0, &ch1);
|
||||
lua_pushnumber(L, ch0);
|
||||
lua_pushnumber(L, ch1);
|
||||
lua_pushnumber(L, error);
|
||||
lua_pushinteger(L, ch0);
|
||||
lua_pushinteger(L, ch1);
|
||||
lua_pushinteger(L, error);
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ static void websocketclient_onReceiveCallback(ws_info *ws, int len, char *messag
|
|||
lua_rawgeti(L, LUA_REGISTRYINDEX, data->onReceive); // load the callback function
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, data->self_ref); // pass itself, #1 callback argument
|
||||
lua_pushlstring(L, message, len); // #2 callback argument
|
||||
lua_pushnumber(L, opCode); // #3 callback argument
|
||||
lua_pushinteger(L, opCode); // #3 callback argument
|
||||
luaL_pcallx(L, 3, 0);
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ static void websocketclient_onCloseCallback(ws_info *ws, int errorCode) {
|
|||
if (data->onClose != LUA_NOREF) {
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, data->onClose); // load the callback function
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, data->self_ref); // pass itself, #1 callback argument
|
||||
lua_pushnumber(L, errorCode); // pass the error code, #2 callback argument
|
||||
lua_pushinteger(L, errorCode); // pass the error code, #2 callback argument
|
||||
luaL_pcallx(L, 2, 0);
|
||||
}
|
||||
|
||||
|
@ -284,7 +284,7 @@ static int websocketclient_gc(lua_State *L) {
|
|||
if (ws->connectionState != 4) { // only call if connection open
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, data->onClose);
|
||||
|
||||
lua_pushnumber(L, -100);
|
||||
lua_pushinteger(L, -100);
|
||||
luaL_pcallx(L, 1, 0);
|
||||
}
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, data->onClose);
|
||||
|
|
|
@ -228,15 +228,15 @@ static int wifi_getcountry( lua_State* L ){
|
|||
lua_rawset(L, -3);
|
||||
|
||||
lua_pushstring(L, "start_ch");
|
||||
lua_pushnumber(L, cfg.schan);
|
||||
lua_pushinteger(L, cfg.schan);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
lua_pushstring(L, "end_ch");
|
||||
lua_pushnumber(L, (cfg.schan + cfg.nchan)-1);
|
||||
lua_pushinteger(L, (cfg.schan + cfg.nchan)-1);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
lua_pushstring(L, "policy");
|
||||
lua_pushnumber(L, cfg.policy);
|
||||
lua_pushinteger(L, cfg.policy);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
return 1;
|
||||
|
@ -276,7 +276,7 @@ static int wifi_setcountry( lua_State* L ){
|
|||
lua_getfield(L, 1, "start_ch");
|
||||
if (!lua_isnil(L, -1)){
|
||||
if(lua_isnumber(L, -1)){
|
||||
start_ch = (uint8)luaL_checknumber(L, -1);
|
||||
start_ch = (uint8)luaL_checkinteger(L, -1);
|
||||
luaL_argcheck(L, (start_ch >= 1 && start_ch <= 14), 1, "start_ch: Range:1-14");
|
||||
cfg.schan = start_ch;
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ static int wifi_setcountry( lua_State* L ){
|
|||
lua_getfield(L, 1, "end_ch");
|
||||
if (!lua_isnil(L, -1)){
|
||||
if(lua_isnumber(L, -1)){
|
||||
end_ch = (uint8)luaL_checknumber(L, -1);
|
||||
end_ch = (uint8)luaL_checkinteger(L, -1);
|
||||
luaL_argcheck(L, (end_ch >= 1 && end_ch <= 14), 1, "end_ch: Range:1-14");
|
||||
luaL_argcheck(L, (end_ch >= cfg.schan), 1, "end_ch: can't be less than start_ch");
|
||||
cfg.nchan = (end_ch-cfg.schan)+1; //cfg.nchan must equal total number of channels
|
||||
|
@ -306,7 +306,7 @@ static int wifi_setcountry( lua_State* L ){
|
|||
lua_getfield(L, 1, "policy");
|
||||
if (!lua_isnil(L, -1)){
|
||||
if(lua_isnumber(L, -1)){
|
||||
uint8 policy = (uint8)luaL_checknumber(L, -1);
|
||||
uint8 policy = (uint8)luaL_checkinteger(L, -1);
|
||||
luaL_argcheck(L, (policy == WIFI_COUNTRY_POLICY_AUTO || policy == WIFI_COUNTRY_POLICY_MANUAL), 1, "policy: must be 0 or 1");
|
||||
cfg.policy = policy;
|
||||
}
|
||||
|
@ -465,7 +465,7 @@ static int wifi_suspend(lua_State* L)
|
|||
if (lua_isnone(L, 1))
|
||||
{
|
||||
// Return current WiFi suspension state
|
||||
lua_pushnumber(L, pmSleep_get_state());
|
||||
lua_pushinteger(L, pmSleep_get_state());
|
||||
return 1; // Return WiFi suspension state
|
||||
}
|
||||
|
||||
|
@ -670,7 +670,7 @@ static int wifi_station_get_ap_info4lua( lua_State* L )
|
|||
char debug_temp[128];
|
||||
#endif
|
||||
lua_newtable(L);
|
||||
lua_pushnumber(L, number_of_aps);
|
||||
lua_pushinteger(L, number_of_aps);
|
||||
lua_setfield(L, -2, "qty");
|
||||
WIFI_DBG("\n\t# of APs stored in flash:%d\n", number_of_aps);
|
||||
WIFI_DBG(" %-6s %-32s %-64s %-17s\n", "index:", "ssid:", "password:", "bssid:");
|
||||
|
@ -709,7 +709,7 @@ static int wifi_station_get_ap_info4lua( lua_State* L )
|
|||
#if defined(WIFI_DEBUG)
|
||||
WIFI_DBG("%s%-17s \n", debug_temp, temp);
|
||||
#endif
|
||||
lua_pushnumber(L, i+1); //Add one, so that AP index follows Lua Conventions
|
||||
lua_pushinteger(L, i+1); //Add one, so that AP index follows Lua Conventions
|
||||
lua_insert(L, -2);
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
|
@ -737,7 +737,7 @@ static int wifi_station_change_ap( lua_State* L )
|
|||
// Lua: wifi.setapnumber(number_of_aps_to_save)
|
||||
static int wifi_station_get_ap_index( lua_State* L )
|
||||
{
|
||||
lua_pushnumber(L, wifi_station_get_current_ap_id()+1);
|
||||
lua_pushinteger(L, wifi_station_get_current_ap_id()+1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -978,7 +978,7 @@ static int wifi_station_config( lua_State* L )
|
|||
if (lua_isfunction(L, -1))
|
||||
{
|
||||
L_temp = lua_newthread(L);
|
||||
lua_pushnumber(L, EVENT_STAMODE_CONNECTED);
|
||||
lua_pushinteger(L, EVENT_STAMODE_CONNECTED);
|
||||
lua_pushvalue(L, -3);
|
||||
lua_xmove(L, L_temp, 2);
|
||||
wifi_event_monitor_register(L_temp);
|
||||
|
@ -996,7 +996,7 @@ static int wifi_station_config( lua_State* L )
|
|||
if (lua_isfunction(L, -1))
|
||||
{
|
||||
L_temp = lua_newthread(L);
|
||||
lua_pushnumber(L, EVENT_STAMODE_DISCONNECTED);
|
||||
lua_pushinteger(L, EVENT_STAMODE_DISCONNECTED);
|
||||
lua_pushvalue(L, -3);
|
||||
lua_xmove(L, L_temp, 2);
|
||||
wifi_event_monitor_register(L_temp);
|
||||
|
@ -1014,7 +1014,7 @@ static int wifi_station_config( lua_State* L )
|
|||
if (lua_isfunction(L, -1))
|
||||
{
|
||||
L_temp = lua_newthread(L);
|
||||
lua_pushnumber(L, EVENT_STAMODE_AUTHMODE_CHANGE);
|
||||
lua_pushinteger(L, EVENT_STAMODE_AUTHMODE_CHANGE);
|
||||
lua_pushvalue(L, -3);
|
||||
lua_xmove(L, L_temp, 2);
|
||||
wifi_event_monitor_register(L_temp);
|
||||
|
@ -1032,7 +1032,7 @@ static int wifi_station_config( lua_State* L )
|
|||
if (lua_isfunction(L, -1))
|
||||
{
|
||||
L_temp = lua_newthread(L);
|
||||
lua_pushnumber(L, EVENT_STAMODE_GOT_IP);
|
||||
lua_pushinteger(L, EVENT_STAMODE_GOT_IP);
|
||||
lua_pushvalue(L, -3);
|
||||
lua_xmove(L, L_temp, 2);
|
||||
wifi_event_monitor_register(L_temp);
|
||||
|
@ -1050,7 +1050,7 @@ static int wifi_station_config( lua_State* L )
|
|||
if (lua_isfunction(L, -1))
|
||||
{
|
||||
L_temp = lua_newthread(L);
|
||||
lua_pushnumber(L, EVENT_STAMODE_DHCP_TIMEOUT);
|
||||
lua_pushinteger(L, EVENT_STAMODE_DHCP_TIMEOUT);
|
||||
lua_pushvalue(L, -3);
|
||||
lua_xmove(L, L_temp, 2);
|
||||
wifi_event_monitor_register(L_temp);
|
||||
|
@ -1111,7 +1111,7 @@ static int wifi_station_connect4lua( lua_State* L )
|
|||
{
|
||||
#ifdef WIFI_SDK_EVENT_MONITOR_ENABLE
|
||||
if(lua_isfunction(L, 1)){
|
||||
lua_pushnumber(L, EVENT_STAMODE_CONNECTED);
|
||||
lua_pushinteger(L, EVENT_STAMODE_CONNECTED);
|
||||
lua_pushvalue(L, 1);
|
||||
lua_remove(L, 1);
|
||||
wifi_event_monitor_register(L);
|
||||
|
@ -1126,7 +1126,7 @@ static int wifi_station_disconnect4lua( lua_State* L )
|
|||
{
|
||||
#ifdef WIFI_SDK_EVENT_MONITOR_ENABLE
|
||||
if(lua_isfunction(L, 1)){
|
||||
lua_pushnumber(L, EVENT_STAMODE_DISCONNECTED);
|
||||
lua_pushinteger(L, EVENT_STAMODE_DISCONNECTED);
|
||||
lua_pushvalue(L, 1);
|
||||
lua_remove(L, 1);
|
||||
wifi_event_monitor_register(L);
|
||||
|
@ -1214,7 +1214,7 @@ static int wifi_station_listap( lua_State* L )
|
|||
{
|
||||
if( lua_isnumber(L, -1) ) // deal with the ssid string
|
||||
{
|
||||
channel = luaL_checknumber( L, -1);
|
||||
channel = luaL_checkinteger( L, -1);
|
||||
if(!(channel>=0 && channel<=13))
|
||||
return luaL_error( L, "channel: 0 or 1-13" );
|
||||
scan_cfg.channel=channel;
|
||||
|
@ -1231,7 +1231,7 @@ static int wifi_station_listap( lua_State* L )
|
|||
{
|
||||
if( lua_isnumber(L, -1) ) // deal with the ssid string
|
||||
{
|
||||
show_hidden = luaL_checknumber( L, -1);
|
||||
show_hidden = luaL_checkinteger( L, -1);
|
||||
if(show_hidden!=0 && show_hidden!=1)
|
||||
return luaL_error( L, "show_hidden: 0 or 1" );
|
||||
scan_cfg.show_hidden=show_hidden;
|
||||
|
@ -1457,15 +1457,15 @@ static int wifi_ap_getconfig( lua_State* L, bool get_flash_cfg)
|
|||
lua_pushstring(L, temp);
|
||||
lua_setfield(L, -2, "pwd");
|
||||
}
|
||||
lua_pushnumber(L, config.authmode);
|
||||
lua_pushinteger(L, config.authmode);
|
||||
lua_setfield(L, -2, "auth");
|
||||
lua_pushnumber(L, config.channel);
|
||||
lua_pushinteger(L, config.channel);
|
||||
lua_setfield(L, -2, "channel");
|
||||
lua_pushboolean(L, (bool)config.ssid_hidden);
|
||||
lua_setfield(L, -2, "hidden");
|
||||
lua_pushnumber(L, config.max_connection);
|
||||
lua_pushinteger(L, config.max_connection);
|
||||
lua_setfield(L, -2, "max");
|
||||
lua_pushnumber(L, config.beacon_interval);
|
||||
lua_pushinteger(L, config.beacon_interval);
|
||||
lua_setfield(L, -2, "beacon");
|
||||
return 1;
|
||||
}
|
||||
|
@ -1696,7 +1696,7 @@ static int wifi_ap_config( lua_State* L )
|
|||
if (lua_isfunction(L, -1))
|
||||
{
|
||||
L_temp = lua_newthread(L);
|
||||
lua_pushnumber(L, EVENT_SOFTAPMODE_STACONNECTED);
|
||||
lua_pushinteger(L, EVENT_SOFTAPMODE_STACONNECTED);
|
||||
lua_pushvalue(L, -3);
|
||||
lua_xmove(L, L_temp, 2);
|
||||
wifi_event_monitor_register(L_temp);
|
||||
|
@ -1714,7 +1714,7 @@ static int wifi_ap_config( lua_State* L )
|
|||
if (lua_isfunction(L, -1))
|
||||
{
|
||||
L_temp = lua_newthread(L);
|
||||
lua_pushnumber(L, EVENT_SOFTAPMODE_STADISCONNECTED);
|
||||
lua_pushinteger(L, EVENT_SOFTAPMODE_STADISCONNECTED);
|
||||
lua_pushvalue(L, -3);
|
||||
lua_xmove(L, L_temp, 2);
|
||||
wifi_event_monitor_register(L_temp);
|
||||
|
@ -1732,7 +1732,7 @@ static int wifi_ap_config( lua_State* L )
|
|||
if (lua_isfunction(L, -1))
|
||||
{
|
||||
L_temp = lua_newthread(L);
|
||||
lua_pushnumber(L, EVENT_SOFTAPMODE_PROBEREQRECVED);
|
||||
lua_pushinteger(L, EVENT_SOFTAPMODE_PROBEREQRECVED);
|
||||
lua_pushvalue(L, -3);
|
||||
lua_xmove(L, L_temp, 2);
|
||||
wifi_event_monitor_register(L_temp);
|
||||
|
|
|
@ -35,7 +35,7 @@ void wifi_event_monitor_register_hook(int (*fn)(System_Event_t*)) {
|
|||
// wifi.eventmon.register()
|
||||
int wifi_event_monitor_register(lua_State* L)
|
||||
{
|
||||
uint8 id = (uint8)luaL_checknumber(L, 1);
|
||||
uint8 id = (uint8)luaL_checkinteger(L, 1);
|
||||
if ( id > EVENT_MAX ) //Check if user is trying to register a callback for a valid event.
|
||||
{
|
||||
return luaL_error( L, "valid wifi events:0-%d", EVENT_MAX );
|
||||
|
@ -87,8 +87,8 @@ static void wifi_event_monitor_handle_event_cb(System_Event_t *evt)
|
|||
size_t queue_len = lua_objlen(L, -1);
|
||||
|
||||
//add event to queue
|
||||
lua_pushnumber(L, queue_len+1);
|
||||
lua_pushnumber(L, evt_ud_ref);
|
||||
lua_pushinteger(L, queue_len+1);
|
||||
lua_pushinteger(L, evt_ud_ref);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
if(queue_len == 0){ //if queue was empty, post task
|
||||
|
@ -109,7 +109,7 @@ static void wifi_event_monitor_process_event_queue(task_param_t param, uint8 pri
|
|||
lua_rawgeti(L, LUA_REGISTRYINDEX, event_queue_ref);
|
||||
int index = 1;
|
||||
lua_rawgeti(L, 1, index);
|
||||
sint32 event_ref = lua_tonumber(L, -1);
|
||||
sint32 event_ref = lua_tointeger(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
//remove event reference from queue
|
||||
|
|
|
@ -463,7 +463,7 @@ static int ws2812_buffer_power(lua_State* L) {
|
|||
total += buffer->values[i];
|
||||
}
|
||||
|
||||
lua_pushnumber(L, total);
|
||||
lua_pushinteger(L, total);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -477,7 +477,7 @@ static int ws2812_buffer_get(lua_State* L) {
|
|||
int i;
|
||||
for (i = 0; i < buffer->colorsPerLed; i++)
|
||||
{
|
||||
lua_pushnumber(L, buffer->values[buffer->colorsPerLed*led+i]);
|
||||
lua_pushinteger(L, buffer->values[buffer->colorsPerLed*led+i]);
|
||||
}
|
||||
|
||||
return buffer->colorsPerLed;
|
||||
|
@ -499,7 +499,7 @@ static int ws2812_buffer_set(lua_State* L) {
|
|||
lua_rawgeti(L, 3, i+1);
|
||||
|
||||
// Convert it as int and store them in buffer
|
||||
buffer->values[buffer->colorsPerLed*led+i] = lua_tonumber(L, -1);
|
||||
buffer->values[buffer->colorsPerLed*led+i] = lua_tointeger(L, -1);
|
||||
}
|
||||
|
||||
// Clean up the stack
|
||||
|
@ -533,7 +533,7 @@ static int ws2812_buffer_set(lua_State* L) {
|
|||
static int ws2812_buffer_size(lua_State* L) {
|
||||
ws2812_buffer * buffer = (ws2812_buffer*)luaL_checkudata(L, 1, "ws2812.buffer");
|
||||
|
||||
lua_pushnumber(L, buffer->size);
|
||||
lua_pushinteger(L, buffer->size);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -206,7 +206,7 @@ static int ws2812_effects_set_color(lua_State* L) {
|
|||
|
||||
static int ws2812_effects_get_speed(lua_State* L) {
|
||||
luaL_argcheck(L, state != NULL, 1, LIBRARY_NOT_INITIALIZED_ERROR_MSG);
|
||||
lua_pushnumber(L, state->speed);
|
||||
lua_pushinteger(L, state->speed);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -221,7 +221,7 @@ static int ws2812_effects_set_speed(lua_State* L) {
|
|||
|
||||
static int ws2812_effects_get_delay(lua_State* L) {
|
||||
luaL_argcheck(L, state != NULL, 1, LIBRARY_NOT_INITIALIZED_ERROR_MSG);
|
||||
lua_pushnumber(L, state->mode_delay);
|
||||
lua_pushinteger(L, state->mode_delay);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ void pcm_data_vu( task_param_t param, uint8 prio )
|
|||
if (cfg->cb_vu_ref != LUA_NOREF) {
|
||||
lua_rawgeti( L, LUA_REGISTRYINDEX, cfg->cb_vu_ref );
|
||||
lua_rawgeti( L, LUA_REGISTRYINDEX, cfg->self_ref );
|
||||
lua_pushnumber( L, (LUA_NUMBER)(cfg->vu_peak) );
|
||||
lua_pushinteger( L, cfg->vu_peak );
|
||||
luaL_pcallx( L, 2, 0 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -350,9 +350,8 @@ void swtmr_cb_register(void* timer_cb_ptr, uint8 suspend_policy){
|
|||
}
|
||||
|
||||
lua_pushstring(L, CB_LIST_STR);
|
||||
lua_rawget(L, -2);
|
||||
|
||||
if(lua_istable(L, -1)){
|
||||
if(lua_rawget(L, -2) == LUA_TTABLE){
|
||||
//cb_list exists, get length of list
|
||||
cb_list_last_idx = lua_objlen(L, -1);
|
||||
}
|
||||
|
@ -366,7 +365,7 @@ void swtmr_cb_register(void* timer_cb_ptr, uint8 suspend_policy){
|
|||
}
|
||||
|
||||
//append new timer cb ptr to table
|
||||
lua_pushnumber(L, cb_list_last_idx+1);
|
||||
lua_pushinteger(L, (lua_Integer) (cb_list_last_idx+1));
|
||||
cb_registry_item_t* reg_item = lua_newuserdata(L, sizeof(cb_registry_item_t));
|
||||
reg_item->tmr_cb_ptr = timer_cb_ptr;
|
||||
reg_item->suspend_policy = suspend_policy;
|
||||
|
|
|
@ -98,7 +98,7 @@ If an invalid `eventtype` is supplied, then an error will be thrown.
|
|||
Gets the current position and press status of the switch
|
||||
|
||||
#### Syntax
|
||||
`pos, press, queue = rotary.getpos(channel)`
|
||||
`pos, press = rotary.getpos(channel)`
|
||||
|
||||
#### Parameters
|
||||
- `channel` The rotary module supports three switches. The channel is either 0, 1 or 2.
|
||||
|
@ -106,7 +106,6 @@ Gets the current position and press status of the switch
|
|||
#### Returns
|
||||
- `pos` The current position of the switch.
|
||||
- `press` A boolean indicating if the switch is currently pressed.
|
||||
- `queue` The number of undelivered callbacks (normally 0).
|
||||
|
||||
#### Example
|
||||
|
||||
|
|
Loading…
Reference in New Issue