Ejemplo n.º 1
0
  do_sleep_opt (L, 2);
  rtctime_deep_sleep_us (us); // does not return
  return 0;
}


// rtctime.dsleep_aligned (aligned_usec, min_usec, option)
static int rtctime_dsleep_aligned (lua_State *L)
{
  if (!rtctime_have_time ())
    return luaL_error (L, "time not available, unable to align");

  uint32_t align_us = luaL_checknumber (L, 1);
  uint32_t min_us = luaL_checknumber (L, 2);
  do_sleep_opt (L, 3);
  rtctime_deep_sleep_until_aligned_us (align_us, min_us); // does not return
  return 0;
}


// Module function map
static const LUA_REG_TYPE rtctime_map[] = {
  { LSTRKEY("set"),            LFUNCVAL(rtctime_set) },
  { LSTRKEY("get"),            LFUNCVAL(rtctime_get) },
  { LSTRKEY("dsleep"),         LFUNCVAL(rtctime_dsleep)  },
  { LSTRKEY("dsleep_aligned"), LFUNCVAL(rtctime_dsleep_aligned) },
  { LNILKEY, LNILVAL }
};

NODEMCU_MODULE(RTCTIME, "rtctime", rtctime_map, NULL);
Ejemplo n.º 2
0
    os_update_cpu_frequency(CPU160MHZ);
  } else {
    REG_CLR_BIT(0x3ff00014,  BIT(0));
    os_update_cpu_frequency(CPU80MHZ);
  }
  new_freq = ets_get_cpu_frequency();
  lua_pushinteger(L, new_freq);
  return 1;
}

// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE node_map[] =
{
  { LSTRKEY( "restart" ), LFUNCVAL( node_restart ) },
  { LSTRKEY( "dsleep" ), LFUNCVAL( node_deepsleep ) },
  { LSTRKEY( "info" ), LFUNCVAL( node_info ) },
  { LSTRKEY( "chipid" ), LFUNCVAL( node_chipid ) },
  { LSTRKEY( "flashid" ), LFUNCVAL( node_flashid ) },
  { LSTRKEY( "flashsize" ), LFUNCVAL( node_flashsize) },
  { LSTRKEY( "heap" ), LFUNCVAL( node_heap ) },
#ifdef DEVKIT_VERSION_0_9
  { LSTRKEY( "key" ), LFUNCVAL( node_key ) },
  { LSTRKEY( "led" ), LFUNCVAL( node_led ) },
#endif
  { LSTRKEY( "input" ), LFUNCVAL( node_input ) },
  { LSTRKEY( "output" ), LFUNCVAL( node_output ) },
// Moved to adc module, use adc.readvdd33()  
// { LSTRKEY( "readvdd33" ), LFUNCVAL( node_readvdd33) },
  { LSTRKEY( "compile" ), LFUNCVAL( node_compile) },
Ejemplo n.º 3
0
  if (result == LUA_ERR_CC_INTOVERFLOW) {
    return luaL_error(L, "value too big or small for target integer type");
  }
  if (result == LUA_ERR_CC_NOTINTEGER) {
    return luaL_error(L, "target lua_Number is integral but fractional value found");
  }

  return 0;
}

#define MIN_OPT_LEVEL   2
#include "lrodefs.h"
const LUA_REG_TYPE file_map[] =
{
  { LSTRKEY( "list" ), LFUNCVAL( file_list ) },
  { LSTRKEY( "slist" ), LFUNCVAL( file_slist ) },
  { LSTRKEY( "format" ), LFUNCVAL( file_format ) },
  { LSTRKEY( "open" ), LFUNCVAL( file_open ) },
  { LSTRKEY( "close" ), LFUNCVAL( file_close ) },
  { LSTRKEY( "write" ), LFUNCVAL( file_write ) },
  { LSTRKEY( "writeline" ), LFUNCVAL( file_writeline ) },
  { LSTRKEY( "read" ), LFUNCVAL( file_read ) },
  { LSTRKEY( "readline" ), LFUNCVAL( file_readline ) },
  { LSTRKEY( "remove" ), LFUNCVAL( file_remove ) },
  { LSTRKEY( "seek" ), LFUNCVAL( file_seek ) },
  { LSTRKEY( "flush" ), LFUNCVAL( file_flush ) },
  { LSTRKEY( "rename" ), LFUNCVAL( file_rename ) },
  { LSTRKEY( "info" ), LFUNCVAL( file_info ) },
  { LSTRKEY( "state" ), LFUNCVAL( file_state ) },
  { LSTRKEY( "compile" ), LFUNCVAL( file_compile ) },
Ejemplo n.º 4
0
  int crc = 0;
  if(lua_isnumber(L, 2))
    crc = lua_tointeger(L, 2);
  if(crc > 65535)
    return luaL_error( L, "wrong arg range" );

  lua_pushinteger( L, onewire_crc16(pdata, (uint16_t)datalen, (uint16_t)crc) );

  return 1;
}
#endif
#endif

// Module function map
static const LUA_REG_TYPE ow_map[] = {
  { LSTRKEY( "setup" ),         LFUNCVAL( ow_setup ) },
  { LSTRKEY( "reset" ),         LFUNCVAL( ow_reset ) },
  { LSTRKEY( "skip" ),          LFUNCVAL( ow_skip ) },
  { LSTRKEY( "select" ),        LFUNCVAL( ow_select ) },
  { LSTRKEY( "write" ),         LFUNCVAL( ow_write ) },
  { LSTRKEY( "write_bytes" ),   LFUNCVAL( ow_write_bytes ) },
  { LSTRKEY( "read" ),          LFUNCVAL( ow_read ) },
  { LSTRKEY( "read_bytes" ),    LFUNCVAL( ow_read_bytes ) },
  { LSTRKEY( "depower" ),       LFUNCVAL( ow_depower ) },
#if ONEWIRE_SEARCH
  { LSTRKEY( "reset_search" ),  LFUNCVAL( ow_reset_search ) },
  { LSTRKEY( "target_search" ), LFUNCVAL( ow_target_search ) },
  { LSTRKEY( "search" ),        LFUNCVAL( ow_search ) },
#endif
#if ONEWIRE_CRC
  { LSTRKEY( "crc8" ),          LFUNCVAL( ow_crc8 ) },
Ejemplo n.º 5
0
        default: {  /* also treat cases `pnLlh' */
          return luaL_error(L, "invalid option " LUA_QL("%%%c") " to "
                               LUA_QL("format"), *(strfrmt - 1));
        }
      }
      luaL_addlstring(&b, buff, c_strlen(buff));
    }
  }
  luaL_pushresult(&b);
  return 1;
}

#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE strlib[] = {
  {LSTRKEY("byte"), LFUNCVAL(str_byte)},
  {LSTRKEY("char"), LFUNCVAL(str_char)},
  {LSTRKEY("dump"), LFUNCVAL(str_dump)},
  {LSTRKEY("find"), LFUNCVAL(str_find)},
  {LSTRKEY("format"), LFUNCVAL(str_format)},
#if LUA_OPTIMIZE_MEMORY > 0 && defined(LUA_COMPAT_GFIND)
  {LSTRKEY("gfind"), LFUNCVAL(gmatch)},
#else
  {LSTRKEY("gfind"), LFUNCVAL(gfind_nodef)},
#endif
  {LSTRKEY("gmatch"), LFUNCVAL(gmatch)},
  {LSTRKEY("gsub"), LFUNCVAL(str_gsub)},
  {LSTRKEY("len"), LFUNCVAL(str_len)},
  {LSTRKEY("lower"), LFUNCVAL(str_lower)},
  {LSTRKEY("match"), LFUNCVAL(str_match)},
  {LSTRKEY("rep"), LFUNCVAL(str_rep)},
Ejemplo n.º 6
0
}


// Lua: elua.version()
static int version( lua_State *L )
{
  lua_pushstring( L, ELUA_STR_VERSION );
  return 1;
}

// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE elua_map[] = 
{
  { LSTRKEY( "egc_setup" ), LFUNCVAL( egc_setup ) },
  { LSTRKEY( "version" ), LFUNCVAL( version ) },
#if LUA_OPTIMIZE_MEMORY > 0
  { LSTRKEY( "EGC_NOT_ACTIVE" ), LNUMVAL( EGC_NOT_ACTIVE ) },
  { LSTRKEY( "EGC_ON_ALLOC_FAILURE" ), LNUMVAL( EGC_ON_ALLOC_FAILURE ) },
  { LSTRKEY( "EGC_ON_MEM_LIMIT" ), LNUMVAL( EGC_ON_MEM_LIMIT ) },
  { LSTRKEY( "EGC_ALWAYS" ), LNUMVAL( EGC_ALWAYS ) },
#endif
  { LNILKEY, LNILVAL }
};

LUALIB_API int luaopen_elua( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
  return 0;
#else
Ejemplo n.º 7
0
  return 1;
}

// Lua: wifi.ap.dhcp.stop()
static int wifi_ap_dhcp_stop( lua_State* L )
{
  lua_pushboolean(L, wifi_softap_dhcps_stop());
  return 1;
}

// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
static const LUA_REG_TYPE wifi_station_map[] =
{
  { LSTRKEY( "getconfig" ), LFUNCVAL ( wifi_station_getconfig ) },
  { LSTRKEY( "config" ), LFUNCVAL ( wifi_station_config ) },
  { LSTRKEY( "connect" ), LFUNCVAL ( wifi_station_connect4lua ) },
  { LSTRKEY( "disconnect" ), LFUNCVAL ( wifi_station_disconnect4lua ) },
  { LSTRKEY( "autoconnect" ), LFUNCVAL ( wifi_station_setauto ) },
  { LSTRKEY( "getip" ), LFUNCVAL ( wifi_station_getip ) },
  { LSTRKEY( "setip" ), LFUNCVAL ( wifi_station_setip ) },
  { LSTRKEY( "getbroadcast" ), LFUNCVAL ( wifi_station_getbroadcast) },
  { LSTRKEY( "getmac" ), LFUNCVAL ( wifi_station_getmac ) },
  { LSTRKEY( "setmac" ), LFUNCVAL ( wifi_station_setmac ) },
  { LSTRKEY( "getap" ), LFUNCVAL ( wifi_station_listap ) },
  { LSTRKEY( "status" ), LFUNCVAL ( wifi_station_status ) },
  { LSTRKEY( "eventMonReg" ), LFUNCVAL ( wifi_station_event_mon_reg ) },
  { LSTRKEY( "eventMonStart" ), LFUNCVAL ( wifi_station_event_mon_start ) },
  { LSTRKEY( "eventMonStop" ), LFUNCVAL ( wifi_station_event_mon_stop ) },
  { LNILKEY, LNILVAL }
Ejemplo n.º 8
0
      case BOOT_REASON_EXPIN_RST:       strcpy(str,"EXPIN_RST");break;
      case BOOT_REASON_WDG_RST:         strcpy(str,"WDG_RST");break;
      case BOOT_REASON_WWDG_RST:        strcpy(str,"WWDG_RST");break;
      case BOOT_REASON_LOWPWR_RST:      strcpy(str,"LOWPWR_RST");break;
      case BOOT_REASON_BOR_RST:         strcpy(str,"BOR_RST");break;
      default:strcpy(str,"NONE");break;
    }
    lua_pushstring(L,str);
    return 1;
}

#define MIN_OPT_LEVEL       2
#include "lrodefs.h"
const LUA_REG_TYPE mcu_map[] =
{
  { LSTRKEY( "ver" ), LFUNCVAL( mcu_version )},
  { LSTRKEY( "info" ), LFUNCVAL( mcu_wifiinfo )},
  { LSTRKEY( "reboot" ), LFUNCVAL( mcu_reboot )},
  { LSTRKEY( "mem" ), LFUNCVAL( mcu_memory )},
  { LSTRKEY( "chipid" ), LFUNCVAL( mcu_chipid )},
  { LSTRKEY( "bootreason" ), LFUNCVAL(mcu_bootreason)},
  { LSTRKEY( "getparams" ), LFUNCVAL(get_params)},
  { LSTRKEY( "sgetparams" ), LFUNCVAL(get_sparams)},
  { LSTRKEY( "setparams" ), LFUNCVAL(set_sparams)},
  { LSTRKEY( "queuepush" ), LFUNCVAL(queue_push)},
  { LSTRKEY( "random" ), LFUNCVAL(mcu_random)},
#if LUA_OPTIMIZE_MEMORY > 0
#endif      
  {LNILKEY, LNILVAL}
};
Ejemplo n.º 9
0
// Lua: iptype = lookup( "name" )
static int net_lookup( lua_State *L )
{
	const char *name = luaL_checkstring( L, 1 );
	elua_net_ip res;

	res = elua_net_lookup( name );
	lua_pushinteger( L, res.ipaddr );
	return 1;
}

// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE net_map[] = {
	{ LSTRKEY( "accept" ), LFUNCVAL( net_accept ) },
	{ LSTRKEY( "packip" ), LFUNCVAL( net_packip ) },
	{ LSTRKEY( "unpackip" ), LFUNCVAL( net_unpackip ) },
	{ LSTRKEY( "connect" ), LFUNCVAL( net_connect ) },
	{ LSTRKEY( "socket" ), LFUNCVAL( net_socket ) },
	{ LSTRKEY( "close" ), LFUNCVAL( net_close ) },
	{ LSTRKEY( "send" ), LFUNCVAL( net_send ) },
	{ LSTRKEY( "recv" ), LFUNCVAL( net_recv ) },
	{ LSTRKEY( "lookup" ), LFUNCVAL( net_lookup ) },
#if LUA_OPTIMIZE_MEMORY > 0
	{ LSTRKEY( "SOCK_STREAM" ), LNUMVAL( ELUA_NET_SOCK_STREAM ) },
	{ LSTRKEY( "SOCK_DGRAM" ), LNUMVAL( ELUA_NET_SOCK_DGRAM ) },
	{ LSTRKEY( "ERR_OK" ), LNUMVAL( ELUA_NET_ERR_OK ) },
	{ LSTRKEY( "ERR_TIMEOUT" ), LNUMVAL( ELUA_NET_ERR_TIMEDOUT ) },
	{ LSTRKEY( "ERR_CLOSED" ), LNUMVAL( ELUA_NET_ERR_CLOSED ) },
	{ LSTRKEY( "ERR_ABORTED" ), LNUMVAL( ELUA_NET_ERR_ABORTED ) },
Ejemplo n.º 10
0
}
#else
extern int pio_mt_index( lua_State* L );
extern int pio_decode( lua_State *L );
#endif



// *****************************************************************************
// Pin function map

#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
static const LUA_REG_TYPE pio_pin_map[] =
{
  { LSTRKEY( "setdir" ), LFUNCVAL ( pio_pin_setdir ) },
  { LSTRKEY( "output" ), LFUNCVAL( pio_pin_output ) },
  { LSTRKEY( "input" ), LFUNCVAL( pio_pin_input ) },
  { LSTRKEY( "setpull" ), LFUNCVAL( pio_pin_setpull ) },
  { LSTRKEY( "setval" ), LFUNCVAL( pio_pin_setval ) },
  { LSTRKEY( "sethigh" ), LFUNCVAL( pio_pin_sethigh ) },
  { LSTRKEY( "setlow" ), LFUNCVAL( pio_pin_setlow ) },
  { LSTRKEY( "getval" ), LFUNCVAL( pio_pin_getval ) },
  { LNILKEY, LNILVAL }
};

static const LUA_REG_TYPE pio_port_map[] =
{
  { LSTRKEY( "setdir" ), LFUNCVAL( pio_port_setdir ) },
  { LSTRKEY( "output" ), LFUNCVAL( pio_port_output ) },
  { LSTRKEY( "input" ), LFUNCVAL( pio_port_input ) },
Ejemplo n.º 11
0
        return luaL_error( L, "invalid number" );
      platform_uart_send( id, ( u8 )len );
    }
    else
    {
      luaL_checktype( L, s, LUA_TSTRING );
      buf = lua_tolstring( L, s, &len );
      for( i = 0; i < len; i ++ )
        platform_uart_send( id, buf[ i ] );
    }
  }
  return 0;
}

// Module function map
static const LUA_REG_TYPE uart_map[] =  {
  { LSTRKEY( "setup" ), LFUNCVAL( uart_setup ) },
  { LSTRKEY( "write" ), LFUNCVAL( uart_write ) },
  { LSTRKEY( "on" ),    LFUNCVAL( uart_on ) },
  { LSTRKEY( "alt" ),   LFUNCVAL( uart_alt ) },
  { LSTRKEY( "STOPBITS_1" ),   LNUMVAL( PLATFORM_UART_STOPBITS_1 ) },
  { LSTRKEY( "STOPBITS_1_5" ), LNUMVAL( PLATFORM_UART_STOPBITS_1_5 ) },
  { LSTRKEY( "STOPBITS_2" ),   LNUMVAL( PLATFORM_UART_STOPBITS_2 ) },
  { LSTRKEY( "PARITY_NONE" ),  LNUMVAL( PLATFORM_UART_PARITY_NONE ) },
  { LSTRKEY( "PARITY_EVEN" ),  LNUMVAL( PLATFORM_UART_PARITY_EVEN ) },
  { LSTRKEY( "PARITY_ODD" ),   LNUMVAL( PLATFORM_UART_PARITY_ODD ) },
  { LNILKEY, LNILVAL }
};

NODEMCU_MODULE(UART, "uart", uart_map, NULL);
Ejemplo n.º 12
0
	{ LSTRKEY( "DeviceInSilentState" ),	 LINTVAL( LORA_DEVICE_IN_SILENT_STATE ) },
	{ LSTRKEY( "DeviceIsNotIdle" ),		 LINTVAL( LORA_DEVICE_DEVICE_IS_NOT_IDLE ) },
	{ LSTRKEY( "Paused" ),		         LINTVAL( LORA_PAUSED ) },
	{ LSTRKEY( "Timeout" ),		         LINTVAL( LORA_TIMEOUT ) },
	{ LSTRKEY( "JoinDenied" ),		     LINTVAL( LORA_JOIN_DENIED ) },
	{ LSTRKEY( "UnexpectedResponse" ),	 LINTVAL( LORA_UNEXPECTED_RESPONSE ) },
	{ LSTRKEY( "NotJoined" ),		     LINTVAL( LORA_NOT_JOINED ) },
	{ LSTRKEY( "RejoinNeeded" ),		 LINTVAL( LORA_REJOIN_NEEDED ) },
	{ LSTRKEY( "InvalidDataLen" ),		 LINTVAL( LORA_INVALID_DATA_LEN ) },
	{ LSTRKEY( "TransmissionFail" ),	 LINTVAL( LORA_TRANSMISSION_FAIL_ACK_NOT_RECEIVED ) },
	{ LSTRKEY( "NotSetup" ),		     LINTVAL( LORA_NOT_SETUP ) },
	{ LSTRKEY( "InvalidArgument" ),		 LINTVAL( LORA_INVALID_PARAM ) },
};

static const LUA_REG_TYPE lora_map[] = {
    { LSTRKEY( "setup" ),        LFUNCVAL( llora_setup ) }, 
    { LSTRKEY( "setDevAddr" ),   LFUNCVAL( llora_set_setDevAddr ) }, 
    { LSTRKEY( "setDevEui" ),    LFUNCVAL( llora_set_DevEui ) }, 
    { LSTRKEY( "setAppEui" ),    LFUNCVAL( llora_set_AppEui ) }, 
    { LSTRKEY( "setAppKey" ),    LFUNCVAL( llora_set_AppKey ) }, 
    { LSTRKEY( "setNwksKey" ),   LFUNCVAL( llora_set_NwkSKey ) }, 
    { LSTRKEY( "setAppsKey" ),   LFUNCVAL( llora_set_AppSKey ) }, 
    { LSTRKEY( "setAppKey" ),    LFUNCVAL( llora_set_AppKey ) }, 
    { LSTRKEY( "setDr" ),        LFUNCVAL( llora_set_Dr ) }, 
    { LSTRKEY( "setAdr" ),       LFUNCVAL( llora_set_Adr ) }, 
    { LSTRKEY( "setRetX" ),      LFUNCVAL( llora_set_RetX ) }, 
    { LSTRKEY( "setLinkChk" ),   LFUNCVAL( llora_set_LinkChk ) }, // MUST DO
    { LSTRKEY( "setRxDelay1" ),  LFUNCVAL( llora_nothing ) }, 
    { LSTRKEY( "setAr" ),        LFUNCVAL( llora_set_Ar ) }, 
    { LSTRKEY( "setRx2" ),       LFUNCVAL( llora_nothing ) }, // MUST DO
    { LSTRKEY( "setChFreq" ),    LFUNCVAL( llora_nothing ) }, // MUST DO
Ejemplo n.º 13
0
    luaL_checkstack(L, 40, "");  /* assume array is smaller than 2^40 */
    if (!lua_isnoneornil(L, 2))  /* is there a 2nd argument? */
      luaL_checktype(L, 2, LUA_TFUNCTION);  /* must be a function */
    lua_settop(L, 2);  /* make sure there are two arguments */
    auxsort(L, 1, (unsigned int)n, 0u);
  }
  return 0;
}

/* }====================================================== */


#include "modules.h"

static const LUA_REG_TYPE tab_funcs[] = {
  { LSTRKEY( "concat" ),		LFUNCVAL( tconcat ) },
#if defined(LUA_COMPAT_MAXN)
  { LSTRKEY( "maxn" ),			LFUNCVAL( maxn ) },
#endif
  { LSTRKEY( "insert" ),		LFUNCVAL( tinsert ) },
  { LSTRKEY( "pack" ),			LFUNCVAL( pack ) },
  { LSTRKEY( "unpack" ),		LFUNCVAL( unpack ) },
  { LSTRKEY( "remove" ),		LFUNCVAL( tremove ) },
  { LSTRKEY( "move" ),			LFUNCVAL( tmove ) },
  { LSTRKEY( "sort" ),			LFUNCVAL( sort ) },
  { LNILKEY, LNILVAL }
};


LUAMOD_API int luaopen_table (lua_State *L) {
 #if !LUA_USE_ROTABLE
Ejemplo n.º 14
0
      MicoUartSend( LUA_USR_UART,(char*)len,1);
    }
    else
    {
      luaL_checktype( L, s, LUA_TSTRING );
      buf = lua_tolstring( L, s, &len );
      MicoUartSend( LUA_USR_UART, buf,len);
    }
  }
  return 0;
}
#define MIN_OPT_LEVEL   2
#include "lrodefs.h"
const LUA_REG_TYPE uart_map[] =
{
  { LSTRKEY( "setup" ), LFUNCVAL( uart_setup )},
  { LSTRKEY( "on" ), LFUNCVAL( uart_on )},
  { LSTRKEY( "send" ), LFUNCVAL( uart_send )},
#if LUA_OPTIMIZE_MEMORY > 0
#endif      
  {LNILKEY, LNILVAL}
};

LUALIB_API int luaopen_uart(lua_State *L)
{
#if LUA_OPTIMIZE_MEMORY > 0
    return 0;
#else  
  luaL_register( L, EXLIB_UART, uart_map );
  return 1;
#endif
Ejemplo n.º 15
0
  y      = luaL_checkinteger(L, 3);
  width  = luaL_checkinteger(L, 4);
  height = luaL_checkinteger(L, 5);
  lm3s_disp_imageDraw(( const unsigned char* )img, x, y, width, height);
  return 0; 
}   



#define MIN_OPT_LEVEL 2
#include "lrodefs.h"  

// Module function map
const LUA_REG_TYPE disp_map[] =
{ 
  { LSTRKEY( "init" ),  LFUNCVAL( disp_init ) },
  { LSTRKEY( "enable" ),  LFUNCVAL( disp_enable ) },
  { LSTRKEY( "disable" ), LFUNCVAL( disp_disable ) },
  { LSTRKEY( "on" ), LFUNCVAL( disp_on ) },    
  { LSTRKEY( "off" ), LFUNCVAL( disp_off ) },
  { LSTRKEY( "clear" ), LFUNCVAL( disp_clear ) },
  { LSTRKEY( "print" ), LFUNCVAL( disp_stringDraw ) },
  { LSTRKEY( "draw" ), LFUNCVAL( disp_imageDraw ) },  
  { LNILKEY, LNILVAL }
};

LUALIB_API int luaopen_disp( lua_State *L )
{
  LREGISTER( L, AUXLIB_DISP, disp_map );
}  
Ejemplo n.º 16
0
    return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);
}


static int f_flush (lua_State *L) {
    return pushresult(L, fflush(tofile(L)) == 0, NULL);
}

#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
#if LUA_OPTIMIZE_MEMORY == 2
const LUA_REG_TYPE iolib_funcs[] = {
#else
const LUA_REG_TYPE iolib[] = {
#endif
    {LSTRKEY("close"), LFUNCVAL(io_close)},
    {LSTRKEY("flush"), LFUNCVAL(io_flush)},
    {LSTRKEY("input"), LFUNCVAL(io_input)},
    {LSTRKEY("lines"), LFUNCVAL(io_lines)},
    {LSTRKEY("open"), LFUNCVAL(io_open)},
    {LSTRKEY("output"), LFUNCVAL(io_output)},
    {LSTRKEY("popen"), LFUNCVAL(io_popen)},
    {LSTRKEY("read"), LFUNCVAL(io_read)},
    {LSTRKEY("tmpfile"), LFUNCVAL(io_tmpfile)},
    {LSTRKEY("type"), LFUNCVAL(io_type)},
    {LSTRKEY("write"), LFUNCVAL(io_write)},
    {LNILKEY, LNILVAL}
};

#if LUA_OPTIMIZE_MEMORY == 2
static int luaL_index(lua_State *L) {
Ejemplo n.º 17
0
    lua_pushinteger( L, idtype );
    lua_pushlstring( L, ( const char * )data, ( size_t )len );
  
    return 3;
  }
  else
    return 0;
}


// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE can_map[] = 
{
  { LSTRKEY( "setup" ),  LFUNCVAL( can_setup ) },
  { LSTRKEY( "send" ),  LFUNCVAL( can_send ) },  
  { LSTRKEY( "recv" ),  LFUNCVAL( can_recv ) },
#if LUA_OPTIMIZE_MEMORY > 0
  { LSTRKEY( "ID_STD" ), LNUMVAL( ELUA_CAN_ID_STD ) },
  { LSTRKEY( "ID_EXT" ), LNUMVAL( ELUA_CAN_ID_EXT ) },
#endif
  { LNILKEY, LNILVAL }
};

LUALIB_API int luaopen_can( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
  return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
  luaL_register( L, AUXLIB_CAN, can_map );
Ejemplo n.º 18
0
  res = strtol( key + 4, &pend, 10 );
  if( *pend != '\0' )
    return 0;
  if( res >= VTMR_NUM_TIMERS )
    return 0;
  lua_pushinteger( L, VTMR_FIRST_ID + res );
  return 1;
}
#endif // #if VTMR_NUM_TIMERS > 0

// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE tmr_map[] = 
{
  { LSTRKEY( "delay" ), LFUNCVAL( tmr_delay ) },
  { LSTRKEY( "read" ), LFUNCVAL( tmr_read ) },
  { LSTRKEY( "start" ), LFUNCVAL( tmr_start ) },
  { LSTRKEY( "gettimediff" ), LFUNCVAL( tmr_gettimediff ) },
  { LSTRKEY( "getdiffnow" ), LFUNCVAL( tmr_getdiffnow ) },
  { LSTRKEY( "getmindelay" ), LFUNCVAL( tmr_getmindelay ) },
  { LSTRKEY( "getmaxdelay" ), LFUNCVAL( tmr_getmaxdelay ) },
  { LSTRKEY( "setclock" ), LFUNCVAL( tmr_setclock ) },
  { LSTRKEY( "getclock" ), LFUNCVAL( tmr_getclock ) },
#ifdef BUILD_LUA_INT_HANDLERS
  { LSTRKEY( "set_match_int" ), LFUNCVAL( tmr_set_match_int ) },
#endif  
#if LUA_OPTIMIZE_MEMORY > 0 && VTMR_NUM_TIMERS > 0
  { LSTRKEY( "__metatable" ), LROVAL( tmr_map ) },
#endif
#if VTMR_NUM_TIMERS > 0  
Ejemplo n.º 19
0
  return 1;
}

#endif


static int math_randomseed (lua_State *L) {
  srand(luaL_checkint(L, 1));
  return 0;
}

#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE math_map[] = {
#ifdef LUA_NUMBER_INTEGRAL
  {LSTRKEY("abs"),   LFUNCVAL(math_abs)},
  {LSTRKEY("ceil"),  LFUNCVAL(math_identity)},
  {LSTRKEY("floor"), LFUNCVAL(math_identity)},
  {LSTRKEY("max"),   LFUNCVAL(math_max)},
  {LSTRKEY("min"),   LFUNCVAL(math_min)},
  {LSTRKEY("pow"),   LFUNCVAL(math_pow)},
  {LSTRKEY("random"),     LFUNCVAL(math_random)},
  {LSTRKEY("randomseed"), LFUNCVAL(math_randomseed)},
  {LSTRKEY("sqrt"),  LFUNCVAL(math_sqrt)},
#if LUA_OPTIMIZE_MEMORY > 0
  {LSTRKEY("huge"),  LNUMVAL(LONG_MAX)},
#endif
#else
  {LSTRKEY("abs"),   LFUNCVAL(math_abs)},
  // {LSTRKEY("acos"),  LFUNCVAL(math_acos)},
  // {LSTRKEY("asin"),  LFUNCVAL(math_asin)},
Ejemplo n.º 20
0
  return 1;
}

#endif


static int math_randomseed (lua_State *L) {
  srand(luaL_checkint(L, 1));
  return 0;
}

#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE math_map[] = {
#ifdef LUA_NUMBER_INTEGRAL
  {LSTRKEY("abs"),   LFUNCVAL(math_abs)},
  {LSTRKEY("max"),   LFUNCVAL(math_max)},
  {LSTRKEY("min"),   LFUNCVAL(math_min)},
  {LSTRKEY("random"),     LFUNCVAL(math_random)},
  {LSTRKEY("randomseed"), LFUNCVAL(math_randomseed)},
  {LSTRKEY("sqrt"),  LFUNCVAL(math_sqrt)},
#if LUA_OPTIMIZE_MEMORY > 0
  {LSTRKEY("huge"),  LNUMVAL(LONG_MAX)},
#endif
#else
  {LSTRKEY("abs"),   LFUNCVAL(math_abs)},
  {LSTRKEY("acos"),  LFUNCVAL(math_acos)},
  {LSTRKEY("asin"),  LFUNCVAL(math_asin)},
  {LSTRKEY("atan2"), LFUNCVAL(math_atan2)},
  {LSTRKEY("atan"),  LFUNCVAL(math_atan)},
  {LSTRKEY("ceil"),  LFUNCVAL(math_ceil)},
Ejemplo n.º 21
0
}

int timer_tostring(lua_State *L)
{
    timer_info_t *p = ((timer_info_t *)luaL_checkudata(L, -1, LUA_TIMER));
    lua_pushfstring(L, "timer (%p)", p->timer_id);
    return 1;
}

#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 0
#include "lrodefs.h"

const LUA_REG_TYPE timer_map[] =
{
    {LSTRKEY("create"), LFUNCVAL(timer_create)},
    {LSTRKEY("delete"), LFUNCVAL(timer_delete)},
    {LNILKEY, LNILVAL}
};

const LUA_REG_TYPE timer_table[] = {
  {LSTRKEY("delete"), LFUNCVAL(timer_delete)},
  {LSTRKEY("__gc"), LFUNCVAL(timer_gc)},
  {LSTRKEY("__tostring"), LFUNCVAL(timer_tostring)},
  {LNILKEY, LNILVAL}
};

LUALIB_API int luaopen_timer(lua_State *L)
{
    luaL_newmetatable(L, LUA_TIMER);  /* create metatable for file handles */
    lua_pushvalue(L, -1);  /* push metatable */
Ejemplo n.º 22
0
  int n = aux_getn(L, 1);
  luaL_checkstack(L, 40, "");  /* assume array is smaller than 2^40 */
  if (!lua_isnoneornil(L, 2))  /* is there a 2nd argument? */
    luaL_checktype(L, 2, LUA_TFUNCTION);
  lua_settop(L, 2);  /* make sure there is two arguments */
  auxsort(L, 1, n);
  return 0;
}

/* }====================================================== */


#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE tab_funcs[] = {
  {LSTRKEY("concat"), LFUNCVAL(tconcat)},
  {LSTRKEY("foreach"), LFUNCVAL(foreach)},
  {LSTRKEY("foreachi"), LFUNCVAL(foreachi)},
  {LSTRKEY("getn"), LFUNCVAL(getn)},
  {LSTRKEY("maxn"), LFUNCVAL(maxn)},
  {LSTRKEY("insert"), LFUNCVAL(tinsert)},
  {LSTRKEY("remove"), LFUNCVAL(tremove)},
  {LSTRKEY("setn"), LFUNCVAL(setn)},
  {LSTRKEY("sort"), LFUNCVAL(sort)},
  {LNILKEY, LNILVAL}
};

LUALIB_API int luaopen_table (lua_State *L) {
  LREGISTER(L, LUA_TABLIBNAME, tab_funcs);
}
Ejemplo n.º 23
0
    return 0;
  if( res >= SERMUX_NUM_VUART )
    return 0;
  lua_pushinteger( L, SERMUX_SERVICE_ID_FIRST + res );
  return 1;
#endif
  return 0;
}
#endif // #ifdef BUILD_SERMUX

// Module function map
#define MIN_OPT_LEVEL   2
#include "lrodefs.h"
const LUA_REG_TYPE uart_map[] = 
{
  { LSTRKEY( "setup" ),  LFUNCVAL( uart_setup ) },
  { LSTRKEY( "write" ), LFUNCVAL( uart_write ) },
  { LSTRKEY( "read" ), LFUNCVAL( uart_read ) },
  { LSTRKEY( "getchar" ), LFUNCVAL( uart_getchar ) },
  { LSTRKEY( "set_buffer" ), LFUNCVAL( uart_set_buffer ) },
  { LSTRKEY( "set_flow_control" ), LFUNCVAL( uart_set_flow_control ) },
#if LUA_OPTIMIZE_MEMORY > 0
  { LSTRKEY( "PAR_EVEN" ), LNUMVAL( PLATFORM_UART_PARITY_EVEN ) },
  { LSTRKEY( "PAR_ODD" ), LNUMVAL( PLATFORM_UART_PARITY_ODD ) },
  { LSTRKEY( "PAR_NONE" ), LNUMVAL( PLATFORM_UART_PARITY_NONE ) },
  { LSTRKEY( "PAR_MARK" ), LNUMVAL( PLATFORM_UART_PARITY_MARK ) },
  { LSTRKEY( "PAR_SPACE" ), LNUMVAL( PLATFORM_UART_PARITY_SPACE ) },
  { LSTRKEY( "STOP_1" ), LNUMVAL( PLATFORM_UART_STOPBITS_1 ) },
  { LSTRKEY( "STOP_1_5" ), LNUMVAL( PLATFORM_UART_STOPBITS_1_5 ) },
  { LSTRKEY( "STOP_2" ), LNUMVAL( PLATFORM_UART_STOPBITS_2 ) },
  { LSTRKEY( "NO_TIMEOUT" ), LNUMVAL( 0 ) },
Ejemplo n.º 24
0
Archivo: rtc.c Proyecto: Lasitha78/elua
          case HOUR: t.hours  = value; break;
          case DAY: t.days = value; break;
	  case MONTH: t.month = value; break;
          case YEAR: t.year = value; break;
        };
        break;
      default:
        return luaL_error( L, "Time values must be numbers" );
    };

    lua_pop( L, 1 );
  }

  RTC_SetTime( &t );

  return 0;
}

#define MIN_OPT_LEVEL 2
#include "lrodefs.h"

// xmc4000.rtc.*() module function map
const LUA_REG_TYPE rtc_map[] = {
  { LSTRKEY( "init" ), LFUNCVAL( rtc_init ) },
  { LSTRKEY( "get" ), LFUNCVAL( rtc_get ) },
  { LSTRKEY( "set" ), LFUNCVAL( rtc_set ) },
  { LSTRKEY( "elapsed" ), LFUNCVAL( rtc_elapsed ) },
  { LSTRKEY( "status" ), LFUNCVAL( rtc_status ) },
  { LNILKEY, LNILVAL }
};
Ejemplo n.º 25
0
static void tmr_printSuspended(lua_State* L){
  swtmr_print_suspended();
}

static void tmr_printTimerlist(lua_State* L){
  swtmr_print_timer_list();
}


#endif

// Module function map

static const LUA_REG_TYPE tmr_dyn_map[] = {
	{ LSTRKEY( "register" ),    LFUNCVAL( tmr_register ) },
	{ LSTRKEY( "alarm" ),       LFUNCVAL( tmr_alarm ) },
	{ LSTRKEY( "start" ),       LFUNCVAL( tmr_start ) },
	{ LSTRKEY( "stop" ),        LFUNCVAL( tmr_stop ) },
	{ LSTRKEY( "unregister" ),  LFUNCVAL( tmr_unregister ) },
	{ LSTRKEY( "state" ),       LFUNCVAL( tmr_state ) },
	{ LSTRKEY( "interval" ),    LFUNCVAL( tmr_interval) },
#ifdef TIMER_SUSPEND_ENABLE
	{ LSTRKEY( "suspend" ),      LFUNCVAL( tmr_suspend ) },
  { LSTRKEY( "resume" ),       LFUNCVAL( tmr_resume ) },
#endif
	{ LSTRKEY( "__gc" ),        LFUNCVAL( tmr_unregister ) },
	{ LSTRKEY( "__index" ),     LROVAL( tmr_dyn_map ) },
	{ LNILKEY, LNILVAL }
};
Ejemplo n.º 26
0
     "numeric", "time", NULL};
  const char *l = luaL_optstring(L, 1, NULL);
  int op = luaL_checkoption(L, 2, "all", catnames);
  lua_pushstring(L, setlocale(cat[op], l));
  return 1;
}


static int os_exit (lua_State *L) {
  c_exit(luaL_optint(L, 1, EXIT_SUCCESS));
}

#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE syslib[] = {
  {LSTRKEY("clock"),     LFUNCVAL(os_clock)},
  {LSTRKEY("date"),      LFUNCVAL(os_date)},
#if !defined LUA_NUMBER_INTEGRAL
  {LSTRKEY("difftime"),  LFUNCVAL(os_difftime)},
#endif
  {LSTRKEY("execute"),   LFUNCVAL(os_execute)},
  {LSTRKEY("exit"),      LFUNCVAL(os_exit)},
  {LSTRKEY("getenv"),    LFUNCVAL(os_getenv)},
  {LSTRKEY("remove"),    LFUNCVAL(os_remove)},
  {LSTRKEY("rename"),    LFUNCVAL(os_rename)},
  {LSTRKEY("setlocale"), LFUNCVAL(os_setlocale)},
  {LSTRKEY("time"),      LFUNCVAL(os_time)},
  {LSTRKEY("tmpname"),   LFUNCVAL(os_tmpname)},
  {LNILKEY, LNILVAL}
};
Ejemplo n.º 27
0
Archivo: elua.c Proyecto: am-m/elua
  // "+2" below comes from the string terminator (+1) and the '\n'
  // that will be added by the shell code (+1)
  if( ( cmdcpy = ( char* )malloc( strlen( pcmd ) + 2 ) ) == NULL )
    return luaL_error( L, "not enough memory for elua_shell" );
  strcpy( cmdcpy, pcmd );
  shellh_execute_command( cmdcpy, 0 );
  free( cmdcpy );
  return 0;
}

// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE elua_map[] =
{
  { LSTRKEY( "egc_setup" ), LFUNCVAL( elua_egc_setup ) },
  { LSTRKEY( "version" ), LFUNCVAL( elua_version ) },
  { LSTRKEY( "save_history" ), LFUNCVAL( elua_save_history ) },
  { LSTRKEY( "shell" ), LFUNCVAL( elua_shell ) },
#if LUA_OPTIMIZE_MEMORY > 0
  { LSTRKEY( "EGC_NOT_ACTIVE" ), LNUMVAL( EGC_NOT_ACTIVE ) },
  { LSTRKEY( "EGC_ON_ALLOC_FAILURE" ), LNUMVAL( EGC_ON_ALLOC_FAILURE ) },
  { LSTRKEY( "EGC_ON_MEM_LIMIT" ), LNUMVAL( EGC_ON_MEM_LIMIT ) },
  { LSTRKEY( "EGC_ALWAYS" ), LNUMVAL( EGC_ALWAYS ) },
#endif
  { LNILKEY, LNILVAL }
};

LUALIB_API int luaopen_elua( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
Ejemplo n.º 28
0
static int luaB_yield (lua_State *L) {
  return lua_yield(L, lua_gettop(L));
}


static int luaB_corunning (lua_State *L) {
  if (lua_pushthread(L))
    lua_pushnil(L);  /* main thread is not a coroutine */
  return 1;
}

#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE co_funcs[] = {
  {LSTRKEY("create"), LFUNCVAL(luaB_cocreate)},
  {LSTRKEY("resume"), LFUNCVAL(luaB_coresume)},
  {LSTRKEY("running"), LFUNCVAL(luaB_corunning)},
  {LSTRKEY("status"), LFUNCVAL(luaB_costatus)},
  {LSTRKEY("wrap"), LFUNCVAL(luaB_cowrap)},
  {LSTRKEY("yield"), LFUNCVAL(luaB_yield)},
  {LNILKEY, LNILVAL}
};

/* }====================================================== */


static void auxopen (lua_State *L, const char *name,
                     lua_CFunction f, lua_CFunction u) {
  lua_pushcfunction(L, u);
  lua_pushcclosure(L, f, 1);
Ejemplo n.º 29
0
  help_init( HELP_FILE_NAME ); 
  term_set_mode( TERM_MODE_COLS );
  term_enable_paging( TERM_PAGING_ON );
  help_help( topic );
  term_set_mode( TERM_MODE_ASCII );
  term_enable_paging( TERM_PAGING_OFF );
  help_close();
  return 0;
}

// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE elua_map[] = 
{
  { LSTRKEY( "egc_setup" ), LFUNCVAL( elua_egc_setup ) },
  { LSTRKEY( "version" ), LFUNCVAL( elua_version ) },  
  { LSTRKEY( "save_history" ), LFUNCVAL( elua_save_history ) },
  { LSTRKEY( "strftime" ), LFUNCVAL( elua_strftime ) },
  { LSTRKEY( "fs_mounted" ), LFUNCVAL( elua_fs_mounted ) },
  { LSTRKEY( "help" ), LFUNCVAL( elua_help ) },
#if LUA_OPTIMIZE_MEMORY > 0
  { LSTRKEY( "EGC_NOT_ACTIVE" ), LNUMVAL( EGC_NOT_ACTIVE ) },
  { LSTRKEY( "EGC_ON_ALLOC_FAILURE" ), LNUMVAL( EGC_ON_ALLOC_FAILURE ) },
  { LSTRKEY( "EGC_ON_MEM_LIMIT" ), LNUMVAL( EGC_ON_MEM_LIMIT ) },
  { LSTRKEY( "EGC_ALWAYS" ), LNUMVAL( EGC_ALWAYS ) },
#endif
  { LNILKEY, LNILVAL }
};

LUALIB_API int luaopen_elua( lua_State *L )
Ejemplo n.º 30
0
      }
      else
        idx = 0;
      base->AFR[ idx ] &= ~( 0x0F << ( pin * 4 ) );
      base->AFR[ idx ] |= func << ( pin * 4 );
    }
  }
  return 0;
}

// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h" 
const LUA_REG_TYPE stm32_pio_map[] =
{
  { LSTRKEY( "set_function" ), LFUNCVAL( stm32_pio_set_function ) },
  { LSTRKEY( "GPIO" ), LNUMVAL( PIN_FUNC_GPIO ) },
  { LSTRKEY( "ADC" ), LNUMVAL( PIN_FUNC_ADC ) },
  { LSTRKEY( "AF0" ), LNUMVAL( 0 ) },
  { LSTRKEY( "AF1" ), LNUMVAL( 1 ) },
  { LSTRKEY( "AF2" ), LNUMVAL( 2 ) },
  { LSTRKEY( "AF3" ), LNUMVAL( 3 ) },
  { LSTRKEY( "AF4" ), LNUMVAL( 4 ) },
  { LSTRKEY( "AF5" ), LNUMVAL( 5 ) },
  { LSTRKEY( "AF6" ), LNUMVAL( 6 ) },
  { LSTRKEY( "AF7" ), LNUMVAL( 7 ) },
  { LSTRKEY( "AF8" ), LNUMVAL( 8 ) },
  { LSTRKEY( "AF9" ), LNUMVAL( 9 ) },
  { LSTRKEY( "AF10" ), LNUMVAL( 10 ) },
  { LSTRKEY( "AF11" ), LNUMVAL( 11 ) },
  { LSTRKEY( "AF12" ), LNUMVAL( 12 ) },