Ejemplo n.º 1
0
// Lua: net.createConnection(type, secure)
int net_createConnection( lua_State *L ) {
  int type, secure;

  type = luaL_optlong(L, 1, TYPE_TCP);
  secure = luaL_optlong(L, 2, 0);

  if (type == TYPE_UDP) {
    platform_print_deprecation_note("net.createConnection with net.UDP type", "in next version");
    return net_createUDPSocket( L );
  }
  if (type != TYPE_TCP) return luaL_error(L, "invalid type");
  if (secure) {
    platform_print_deprecation_note("net.createConnection with secure flag", "in next version");
#ifdef TLS_MODULE_PRESENT
    return tls_socket_create( L );
#else
    return luaL_error(L, "secure connections not enabled");
#endif
  }
  net_create(L, TYPE_TCP_CLIENT);
  return 1;
}
Ejemplo n.º 2
0
// Lua: net.createServer(type, timeout)
int net_createServer( lua_State *L ) {
  int type, timeout;

  type = luaL_optlong(L, 1, TYPE_TCP);
  timeout = luaL_optlong(L, 2, 30);

  if (type == TYPE_UDP) {
    platform_print_deprecation_note("net.createServer with net.UDP type", "in next version");
    return net_createUDPSocket( L );
  }
  if (type != TYPE_TCP) return luaL_error(L, "invalid type");

  lnet_userdata *u = net_create(L, TYPE_TCP_SERVER);
  u->server.timeout = timeout;
  return 1;
}
Ejemplo n.º 3
0
// wifi.sta.eventMonReg()
int wifi_station_event_mon_reg(lua_State* L)
{
  platform_print_deprecation_note("wifi.sta.eventmonreg() is replaced by wifi.eventmon.register()", "in the next version");

  uint8 id=(uint8)luaL_checknumber(L, 1);
  if ((id > 5)) // verify user specified a valid wifi status
  {
    return luaL_error( L, "valid wifi status:0-5" );
  }

  if (lua_type(L, 2) == LUA_TFUNCTION || lua_type(L, 2) == LUA_TLIGHTFUNCTION) //check if 2nd item on stack is a function
  {
    lua_pushvalue(L, 2); //push function to top of stack
    register_lua_cb(L, &wifi_station_status_cb_ref[id]);//pop function from top of the stack, register it in the LUA_REGISTRY, then assign returned lua_ref to wifi_station_status_cb_ref[id]
  }
  else
  {
    unregister_lua_cb(L, &wifi_station_status_cb_ref[id]); // unregister user's callback
  }
  return 0;
}