leafo / lua-enet

Bindings to ENet for Lua
http://leafo.net/lua-enet/
85 stars 25 forks source link

Suggestions; adding the following to ENetHost references in Lua. #7

Open fleetcomm opened 11 years ago

fleetcomm commented 11 years ago

/* returns a string referencing the printable ip address of the current host _/ static int host_get_address(luaState l) { ENetHost *host = check_host(l, 1); std::string address; char buff[1024]; enet_address_get_host_ip(&host->address, buff, 1024); address.clear(); address.append(buff); lua_pushstring(l, address.c_str()); return 1; }

/* and in function registry */

static const struct luaL_Reg enet_host_funcs [] = { {"service", host_service}, {"check_events", host_check_events}, {"compress_with_range_coder", host_compress_with_range_coder}, {"connect", host_connect}, {"flush", host_flush}, {"broadcast", host_broadcast}, {"channel_limit", host_channel_limit}, {"bandwidth_limit", host_bandwidth_limit}, {"total_sent_data", host_total_sent_data}, {"total_received_data", host_total_received_data}, {"service_time", host_service_time}, {"peer_count", host_peer_count}, {"get_peer", host_get_peer}, {"get_address", host_get_address}, {NULL, NULL} };

If you find this useful, please add it. I'm currently using that add on function to run local server auto detection.