naev 0.12.6
lua_enet.c File Reference

Lightly modified version of https://github.com/leafo/lua-enet/blob/master/enet.c (rev 97d91e8c4337555425fa751f02f552bbb553f17b, upstream copyright below). More...

#include <stdlib.h>
#include <string.h>
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include <enet/enet.h>
Include dependency graph for lua_enet.c:

Go to the source code of this file.

Macros

#define LUA_COMPAT_MODULE
#define check_host(l, idx)
#define check_peer(l, idx)

Functions

static void parse_address (lua_State *l, const char *addr_str, ENetAddress *address)
size_t find_peer_index (lua_State *l, ENetHost *enet_host, ENetPeer *peer)
static void push_peer (lua_State *l, ENetPeer *peer)
static void push_event (lua_State *l, ENetEvent *event)
static ENetPacket * read_packet (lua_State *l, int idx, enet_uint8 *channel_id)
static int host_create (lua_State *l)
static int linked_version (lua_State *l)
static int host_service (lua_State *l)
static int host_check_events (lua_State *l)
static int host_compress_with_range_coder (lua_State *l)
static int host_connect (lua_State *l)
static int host_flush (lua_State *l)
static int host_broadcast (lua_State *l)
static int host_channel_limit (lua_State *l)
static int host_bandwidth_limit (lua_State *l)
static int host_get_socket_address (lua_State *l)
static int host_total_sent_data (lua_State *l)
static int host_total_received_data (lua_State *l)
static int host_service_time (lua_State *l)
static int host_peer_count (lua_State *l)
static int host_get_peer (lua_State *l)
static int host_gc (lua_State *l)
static int peer_tostring (lua_State *l)
static int peer_ping (lua_State *l)
static int peer_throttle_configure (lua_State *l)
static int peer_round_trip_time (lua_State *l)
static int peer_last_round_trip_time (lua_State *l)
static int peer_ping_interval (lua_State *l)
static int peer_timeout (lua_State *l)
static int peer_disconnect (lua_State *l)
static int peer_disconnect_now (lua_State *l)
static int peer_disconnect_later (lua_State *l)
static int peer_index (lua_State *l)
static int peer_state (lua_State *l)
static int peer_connect_id (lua_State *l)
static int peer_reset (lua_State *l)
static int peer_receive (lua_State *l)
static int peer_send (lua_State *l)
int luaopen_enet (lua_State *l)

Variables

static const struct luaL_Reg enet_funcs []
static const struct luaL_Reg enet_host_funcs []
static const struct luaL_Reg enet_peer_funcs []

Detailed Description

Lightly modified version of https://github.com/leafo/lua-enet/blob/master/enet.c (rev 97d91e8c4337555425fa751f02f552bbb553f17b, upstream copyright below).

Definition in file lua_enet.c.

Macro Definition Documentation

◆ check_host

#define check_host ( l,
idx )
Value:
*(ENetHost**)luaL_checkudata(l, idx, "enet_host")

Definition at line 42 of file lua_enet.c.

◆ check_peer

#define check_peer ( l,
idx )
Value:
*(ENetPeer**)luaL_checkudata(l, idx, "enet_peer")

Definition at line 45 of file lua_enet.c.

◆ LUA_COMPAT_MODULE

#define LUA_COMPAT_MODULE

Copyright (C) 2014 by Leaf Corcoran

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING IN THE SOFTWARE.

Definition at line 36 of file lua_enet.c.

Function Documentation

◆ find_peer_index()

size_t find_peer_index ( lua_State * l,
ENetHost * enet_host,
ENetPeer * peer )

Find the index of a given peer for which we only have the pointer.

Definition at line 99 of file lua_enet.c.

◆ host_bandwidth_limit()

int host_bandwidth_limit ( lua_State * l)
static

Definition at line 412 of file lua_enet.c.

◆ host_broadcast()

int host_broadcast ( lua_State * l)
static

Definition at line 389 of file lua_enet.c.

◆ host_channel_limit()

int host_channel_limit ( lua_State * l)
static

Definition at line 402 of file lua_enet.c.

◆ host_check_events()

int host_check_events ( lua_State * l)
static

Dispatch a single event if available

Definition at line 305 of file lua_enet.c.

◆ host_compress_with_range_coder()

int host_compress_with_range_coder ( lua_State * l)
static

Enables an adaptive order-2 PPM range coder for the transmitted data of all peers.

Definition at line 323 of file lua_enet.c.

◆ host_connect()

int host_connect ( lua_State * l)
static

Connect a host to an address Args: the address [channel_count = 1] [data = 0]

Definition at line 346 of file lua_enet.c.

◆ host_create()

int host_create ( lua_State * l)
static

Create a new host Args: address (nil for client) [peer_count = 64] [channel_count = 1] [in_bandwidth = 0] [out_bandwidth = 0]

Definition at line 220 of file lua_enet.c.

◆ host_flush()

int host_flush ( lua_State * l)
static

Definition at line 380 of file lua_enet.c.

◆ host_gc()

int host_gc ( lua_State * l)
static

Definition at line 501 of file lua_enet.c.

◆ host_get_peer()

int host_get_peer ( lua_State * l)
static

Definition at line 483 of file lua_enet.c.

◆ host_get_socket_address()

int host_get_socket_address ( lua_State * l)
static

Definition at line 423 of file lua_enet.c.

◆ host_peer_count()

int host_peer_count ( lua_State * l)
static

Definition at line 472 of file lua_enet.c.

◆ host_service()

int host_service ( lua_State * l)
static

Serice a host Args: timeout

Return nil on no event an event table on event

Definition at line 283 of file lua_enet.c.

◆ host_service_time()

int host_service_time ( lua_State * l)
static

Definition at line 461 of file lua_enet.c.

◆ host_total_received_data()

int host_total_received_data ( lua_State * l)
static

Definition at line 451 of file lua_enet.c.

◆ host_total_sent_data()

int host_total_sent_data ( lua_State * l)
static

Definition at line 440 of file lua_enet.c.

◆ linked_version()

int linked_version ( lua_State * l)
static

Definition at line 266 of file lua_enet.c.

◆ luaopen_enet()

int luaopen_enet ( lua_State * l)

Definition at line 791 of file lua_enet.c.

◆ parse_address()

void parse_address ( lua_State * l,
const char * addr_str,
ENetAddress * address )
static

Parse address string, eg: :5959 127.0.0.1: website.com:8080

Definition at line 54 of file lua_enet.c.

◆ peer_connect_id()

int peer_connect_id ( lua_State * l)
static

Definition at line 680 of file lua_enet.c.

◆ peer_disconnect()

int peer_disconnect ( lua_State * l)
static

Definition at line 606 of file lua_enet.c.

◆ peer_disconnect_later()

int peer_disconnect_later ( lua_State * l)
static

Definition at line 622 of file lua_enet.c.

◆ peer_disconnect_now()

int peer_disconnect_now ( lua_State * l)
static

Definition at line 614 of file lua_enet.c.

◆ peer_index()

int peer_index ( lua_State * l)
static

Definition at line 630 of file lua_enet.c.

◆ peer_last_round_trip_time()

int peer_last_round_trip_time ( lua_State * l)
static

Definition at line 554 of file lua_enet.c.

◆ peer_ping()

int peer_ping ( lua_State * l)
static

Definition at line 524 of file lua_enet.c.

◆ peer_ping_interval()

int peer_ping_interval ( lua_State * l)
static

Definition at line 566 of file lua_enet.c.

◆ peer_receive()

int peer_receive ( lua_State * l)
static

Definition at line 695 of file lua_enet.c.

◆ peer_reset()

int peer_reset ( lua_State * l)
static

Definition at line 689 of file lua_enet.c.

◆ peer_round_trip_time()

int peer_round_trip_time ( lua_State * l)
static

Definition at line 541 of file lua_enet.c.

◆ peer_send()

int peer_send ( lua_State * l)
static

Send a lua string to a peer Args: packet data, string channel id flags ["reliable", nil]

Definition at line 723 of file lua_enet.c.

◆ peer_state()

int peer_state ( lua_State * l)
static

Definition at line 639 of file lua_enet.c.

◆ peer_throttle_configure()

int peer_throttle_configure ( lua_State * l)
static

Definition at line 530 of file lua_enet.c.

◆ peer_timeout()

int peer_timeout ( lua_State * l)
static

Definition at line 579 of file lua_enet.c.

◆ peer_tostring()

int peer_tostring ( lua_State * l)
static

Definition at line 512 of file lua_enet.c.

◆ push_event()

void push_event ( lua_State * l,
ENetEvent * event )
static

Definition at line 133 of file lua_enet.c.

◆ push_peer()

void push_peer ( lua_State * l,
ENetPeer * peer )
static

Definition at line 111 of file lua_enet.c.

◆ read_packet()

ENetPacket * read_packet ( lua_State * l,
int idx,
enet_uint8 * channel_id )
static

Read a packet off the stack as a string idx is position of string

Definition at line 177 of file lua_enet.c.

Variable Documentation

◆ enet_funcs

const struct luaL_Reg enet_funcs[]
static
Initial value:
= {
{"host_create", host_create},
{"linked_version", linked_version},
{NULL, NULL}
}
static int host_create(lua_State *l)
Definition lua_enet.c:220

Definition at line 740 of file lua_enet.c.

◆ enet_host_funcs

const struct luaL_Reg enet_host_funcs[]
static
Initial value:
= {
{"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},
{"get_socket_address", host_get_socket_address},
{"destroy", host_gc},
{"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},
{NULL, NULL}
}
static int host_service(lua_State *l)
Definition lua_enet.c:283
static int host_compress_with_range_coder(lua_State *l)
Definition lua_enet.c:323
static int host_connect(lua_State *l)
Definition lua_enet.c:346
static int host_check_events(lua_State *l)
Definition lua_enet.c:305

Definition at line 746 of file lua_enet.c.

◆ enet_peer_funcs

const struct luaL_Reg enet_peer_funcs[]
static
Initial value:
= {
{"disconnect", peer_disconnect},
{"disconnect_now", peer_disconnect_now},
{"disconnect_later", peer_disconnect_later},
{"reset", peer_reset},
{"ping", peer_ping},
{"receive", peer_receive},
{"send", peer_send},
{"throttle_configure", peer_throttle_configure},
{"ping_interval", peer_ping_interval},
{"timeout", peer_timeout},
{"index", peer_index},
{"state", peer_state},
{"connect_id", peer_connect_id},
{"round_trip_time", peer_round_trip_time},
{"last_round_trip_time", peer_last_round_trip_time},
{NULL, NULL}
}
static int peer_send(lua_State *l)
Definition lua_enet.c:723

Definition at line 770 of file lua_enet.c.