Unverified Commit 606f9166 authored by Philip Gladstone's avatar Philip Gladstone Committed by GitHub
Browse files

First phase of number to integer conversion (#3221)

parent 0e02c0e5
......@@ -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
......
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