Exemple #1
0
LUALIB_API int luaopen_net( lua_State *L )
{
  int i;
  for(i=0;i<MAX_SOCKET;i++)
  {
    socket[i] = LUA_NOREF;
  }

#if LUA_OPTIMIZE_MEMORY > 0
  luaL_rometatable(L, "net.server", (void *)net_server_map);  // create metatable for net.server
  luaL_rometatable(L, "net.socket", (void *)net_socket_map);  // create metatable for net.socket
  #if 0
  luaL_rometatable(L, "net.array", (void *)net_array_map);  // create metatable for net.array
  #endif
  return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
  int n;
  luaL_register( L, AUXLIB_NET, net_map );

  // Set it as its own metatable
  lua_pushvalue( L, -1 );
  lua_setmetatable( L, -2 );

  // Module constants  
  MOD_REG_NUMBER( L, "TCP", TCP );
  MOD_REG_NUMBER( L, "UDP", UDP );
  
  n = lua_gettop(L);

  // create metatable
  luaL_newmetatable(L, "net.server");
  // metatable.__index = metatable
  lua_pushliteral(L, "__index");
  lua_pushvalue(L,-2);
  lua_rawset(L,-3);
  // Setup the methods inside metatable
  luaL_register( L, NULL, net_server_map );

  lua_settop(L, n);
  // create metatable
  luaL_newmetatable(L, "net.socket");
  // metatable.__index = metatable
  lua_pushliteral(L, "__index");
  lua_pushvalue(L,-2);
  lua_rawset(L,-3);
  // Setup the methods inside metatable
  luaL_register( L, NULL, net_socket_map );
#if 0
  lua_settop(L, n);
  // create metatable
  luaL_newmetatable(L, "net.array");
  // Setup the methods inside metatable
  luaL_register( L, NULL, net_array_map );
#endif
  return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0  
}
Exemple #2
0
int luaopen_net( lua_State *L ) {
  igmp_init();

  luaL_rometatable(L, NET_TABLE_TCP_SERVER, (void *)net_tcpserver_map);
  luaL_rometatable(L, NET_TABLE_TCP_CLIENT, (void *)net_tcpsocket_map);
  luaL_rometatable(L, NET_TABLE_UDP_SOCKET, (void *)net_udpsocket_map);

  return 0;
}
Exemple #3
0
int luaopen_net( lua_State *L ) {
  int i;
  for(i=0;i<MAX_SOCKET;i++)
  {
    socket[i] = LUA_NOREF;
  }

  luaL_rometatable(L, "net.server", (void *)net_server_map);  // create metatable for net.server
  luaL_rometatable(L, "net.socket", (void *)net_socket_map);  // create metatable for net.socket
  #if 0
  luaL_rometatable(L, "net.array", (void *)net_array_map);    // create metatable for net.array
  #endif

  return 0;
}
Exemple #4
0
int luaopen_tmr( lua_State *L ){
	int i;	

	luaL_rometatable(L, "tmr.timer", (void *)tmr_dyn_map);

	for(i=0; i<NUM_TMR; i++){
		alarm_timers[i].lua_ref = LUA_NOREF;
		alarm_timers[i].self_ref = LUA_REFNIL;
		alarm_timers[i].mode = TIMER_MODE_OFF;
		os_timer_disarm(&alarm_timers[i].os);
	}
	last_rtc_time=system_get_rtc_time(); // Right now is time 0
	last_rtc_time_us=0;

	os_timer_disarm(&rtc_timer);
	os_timer_setfn(&rtc_timer, rtc_callback, NULL);
	os_timer_arm(&rtc_timer, 1000, 1);

  SWTIMER_REG_CB(rtc_callback, SWTIMER_RESUME);
  //The function rtc_callback calls the a function that calibrates the SoftRTC for drift in the esp8266's clock.
  //My guess: after the duration of light_sleep there's bound to be some drift in the clock, so a calibration is due.
  SWTIMER_REG_CB(alarm_timer_common, SWTIMER_RESUME);
  //The function alarm_timer_common handles timers created by the developer via tmr.create().
  //No reason not to resume the timers, so resume em'.


	return 0;
}
Exemple #5
0
LUALIB_API int luaopen_mqtt( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
  luaL_rometatable(L, "mqtt.socket", (void *)mqtt_socket_map);  // create metatable for mqtt.socket
  return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
  int n;
  luaL_register( L, AUXLIB_MQTT, mqtt_map );

  // Set it as its own metatable
  lua_pushvalue( L, -1 );
  lua_setmetatable( L, -2 );

  // Module constants  
  // MOD_REG_NUMBER( L, "TCP", TCP );

  // create metatable
  luaL_newmetatable(L, "mqtt.socket");
  // metatable.__index = metatable
  lua_pushliteral(L, "__index");
  lua_pushvalue(L,-2);
  lua_rawset(L,-3);
  // Setup the methods inside metatable
  luaL_register( L, NULL, mqtt_socket_map );

  return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0  
}
static void createmeta (lua_State *L) {
#if LUA_OPTIMIZE_MEMORY == 0
    luaL_newmetatable(L, LUA_FILEHANDLE);  /* create metatable for file handles */
    lua_pushvalue(L, -1);  /* push metatable */
    lua_setfield(L, -2, "__index");  /* metatable.__index = metatable */
    luaL_register(L, NULL, flib);  /* file methods */
#else
    luaL_rometatable(L, LUA_FILEHANDLE, (void *)flib); /* create metatable for file handles */
#endif
}
Exemple #7
0
LUALIB_API int luaopen_package (lua_State *L) {
  int i;
  /* create new type _LOADLIB */
#if LUA_OPTIMIZE_MEMORY == 0
  luaL_newmetatable(L, "_LOADLIB");
  lua_pushlightfunction(L, gctm);
  lua_setfield(L, -2, "__gc");
#else
  luaL_rometatable(L, "_LOADLIB", (void*)lmt);
#endif
  /* create `package' table */
  luaL_register_light(L, LUA_LOADLIBNAME, pk_funcs);
#if defined(LUA_COMPAT_LOADLIB) 
  lua_getfield(L, -1, "loadlib");
  lua_setfield(L, LUA_GLOBALSINDEX, "loadlib");
#endif
  lua_pushvalue(L, -1);
  lua_replace(L, LUA_ENVIRONINDEX);
  /* create `loaders' table */
  lua_createtable(L, sizeof(loaders)/sizeof(loaders[0]) - 1, 0);
  /* fill it with pre-defined loaders */
  for (i=0; loaders[i] != NULL; i++) {
    lua_pushcfunction(L, loaders[i]);
    lua_rawseti(L, -2, i+1);
  }
  lua_setfield(L, -2, "loaders");  /* put it in field `loaders' */
  setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT);  /* set field `path' */
  setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */
  /* store config information */
  lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n"
                     LUA_EXECDIR "\n" LUA_IGMARK);
  lua_setfield(L, -2, "config");
  /* set field `loaded' */
  luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2);
  lua_setfield(L, -2, "loaded");
  /* set field `preload' */
  lua_newtable(L);
  lua_setfield(L, -2, "preload");
  lua_pushvalue(L, LUA_GLOBALSINDEX);
  luaL_register(L, NULL, ll_funcs);  /* open lib into global table */
  lua_pop(L, 1);
  return 1;  /* return 'package' table */
}
Exemple #8
0
int luaopen_tmr( lua_State *L ){
	int i;	

	luaL_rometatable(L, "tmr.timer", (void *)tmr_dyn_map);

	for(i=0; i<NUM_TMR; i++){
		alarm_timers[i].lua_ref = LUA_NOREF;
		alarm_timers[i].self_ref = LUA_REFNIL;
		alarm_timers[i].mode = TIMER_MODE_OFF;
		ets_timer_disarm(&alarm_timers[i].os);
	}
	last_rtc_time=system_get_rtc_time(); // Right now is time 0
	last_rtc_time_us=0;

	ets_timer_disarm(&rtc_timer);
	ets_timer_setfn(&rtc_timer, rtc_callback, NULL);
	ets_timer_arm_new(&rtc_timer, 1000, 1, 1);
	return 0;
}
Exemple #9
0
int luaopen_pcm( lua_State *L ) {
  luaL_rometatable( L, "pcm.driver", (void *)pcm_driver_map );  // create metatable
  return 0;
}
Exemple #10
0
int luaopen_ucg( lua_State *L )
{
    luaL_rometatable(L, "ucg.display", (void *)lucg_display_map);  // create metatable
    return 0;
}
Exemple #11
0
int luaopen_ws2812(lua_State *L) {
  // TODO: Make sure that the GPIO system is initialized
  luaL_rometatable(L, "ws2812.buffer", (void *)ws2812_buffer_map);  // create metatable for ws2812.buffer
  return 0;
}