Skip to content

Networking (function list)

Status: Implemented (API 1.24). Generated from client/clight/idl/clight_api.json by tools/docs/gen_api_reference.py; do not edit by hand. 21 functions, the newest from API 1.0.

Explanations and examples: Networking. Every function of the net module is listed here in table order. The details of each function follow the table, in the same order. Side: where the function works (server, client, both). Context: the thread it may be called on (Conventions). Since: the API version that added it.

C function Lua Side Context Since
cl_payload_register cl.net.payload_register both MAIN 1.0
cl_net_send_to_server cl.net.send_to_server client TICK 1.0
cl_net_send_to_player cl.net.send_to_player server TICK 1.0
cl_buf_create cl.buf.create both ANY 1.0
cl_buf_release cl.buf.release both ANY 1.0
cl_buf_size cl.buf.size both ANY 1.0
cl_buf_read_bytes (not in Lua) both ANY 1.0
cl_buf_write_bytes (not in Lua) both ANY 1.0
cl_buf_write_varint cl.buf.write_varint both ANY 1.0
cl_buf_write_i32 cl.buf.write_i32 both ANY 1.0
cl_buf_write_i64 cl.buf.write_i64 both ANY 1.0
cl_buf_write_f32 cl.buf.write_f32 both ANY 1.0
cl_buf_write_f64 cl.buf.write_f64 both ANY 1.0
cl_buf_write_str cl.buf.write_str both ANY 1.0
cl_buf_read_varint cl.buf.read_varint both ANY 1.0
cl_buf_read_i32 cl.buf.read_i32 both ANY 1.0
cl_buf_read_i64 cl.buf.read_i64 both ANY 1.0
cl_buf_read_f32 cl.buf.read_f32 both ANY 1.0
cl_buf_read_f64 cl.buf.read_f64 both ANY 1.0
cl_buf_read_str cl.buf.read_str both ANY 1.0
cl_buf_remaining cl.buf.remaining both ANY 1.0

cl_payload_register

cl_result cl_payload_register(const cl_payload_desc* desc, cl_holder* out);
  • Side: both. Context: MAIN (startup (main thread)). Since: API 1.0.
  • Lua: cl.net.payload_register
  • C++: clight::net::payload_register(const cl_payload_desc* desc) → Expected<cl_holder>
  • The last parameter receives the result. Lua returns it; C++ returns it in Expected<T>.
  • Returns CL_OK or an error code (Error codes). Lua raises a cl.Error on failure.

cl_net_send_to_server

cl_result cl_net_send_to_server(cl_str id, cl_buf data);
  • Side: client. Context: TICK (tick thread). Since: API 1.0.
  • Lua: cl.net.send_to_server
  • C++: clight::net::send_to_server(std::string_view id, cl_buf data) → Expected<void>
  • Returns CL_OK or an error code (Error codes). Lua raises a cl.Error on failure.

cl_net_send_to_player

cl_result cl_net_send_to_player(cl_entity player, cl_str id, cl_buf data);
  • Side: server. Context: TICK (tick thread). Since: API 1.0.
  • Lua: cl.net.send_to_player, entity:send_to_player(...)
  • C++: Entity::net_send_to_player(std::string_view id, cl_buf data) → Expected<void>; clight::net::send_to_player(Entity player, std::string_view id, cl_buf data) → Expected<void>
  • Returns CL_OK or an error code (Error codes). Lua raises a cl.Error on failure.

cl_buf_create

cl_buf cl_buf_create(size_t reserve);
  • Side: both. Context: ANY (any thread). Since: API 1.0.
  • Lua: cl.buf.create, cl.net.buf_create (old name)
  • C++: clight::net::buf_create(size_t reserve) → Buf
  • The returned handle is owned: release it ©, or let the RAII class do it (C++). Lua releases it when it is collected (or at once with local s <close> = ...).

cl_buf_release

void cl_buf_release(cl_buf b);
  • Side: both. Context: ANY (any thread). Since: API 1.0.
  • Lua: cl.buf.release, buf:release(...), cl.net.buf_release (old name)
  • C++: Buf::release() → void; clight::net::buf_release(cl_buf b) → void

cl_buf_size

size_t cl_buf_size(cl_buf b);
  • Side: both. Context: ANY (any thread). Since: API 1.0.
  • Lua: cl.buf.size, buf:size(...), cl.net.buf_size (old name)
  • C++: Buf::size() → size_t; clight::net::buf_size(cl_buf b) → size_t

cl_buf_read_bytes

cl_result cl_buf_read_bytes(cl_buf b, void* p, size_t n, size_t* out);

Copies up to n unread bytes into p (advances the read position).

  • Side: both. Context: ANY (any thread). Since: API 1.0.
  • Lua: (not in Lua)
  • C++: Buf::read_bytes(void* p, size_t n) → Expected<size_t>; clight::net::buf_read_bytes(cl_buf b, void* p, size_t n) → Expected<size_t>
  • The last parameter receives the result. Lua returns it; C++ returns it in Expected<T>.
  • Returns CL_OK or an error code (Error codes). Lua raises a cl.Error on failure.

cl_buf_write_bytes

cl_result cl_buf_write_bytes(cl_buf b, const void* p, size_t n);
  • Side: both. Context: ANY (any thread). Since: API 1.0.
  • Lua: (not in Lua)
  • C++: Buf::write_bytes(const void* p, size_t n) → Expected<void>; clight::net::buf_write_bytes(cl_buf b, const void* p, size_t n) → Expected<void>
  • Returns CL_OK or an error code (Error codes). Lua raises a cl.Error on failure.

cl_buf_write_varint

cl_result cl_buf_write_varint(cl_buf b, int32_t v);
  • Side: both. Context: ANY (any thread). Since: API 1.0.
  • Lua: cl.buf.write_varint, buf:write_varint(...), cl.net.buf_write_varint (old name)
  • C++: Buf::write_varint(int32_t v) → Expected<void>; clight::net::buf_write_varint(cl_buf b, int32_t v) → Expected<void>
  • Returns CL_OK or an error code (Error codes). Lua raises a cl.Error on failure.

cl_buf_write_i32

cl_result cl_buf_write_i32(cl_buf b, int32_t v);
  • Side: both. Context: ANY (any thread). Since: API 1.0.
  • Lua: cl.buf.write_i32, buf:write_i32(...), cl.net.buf_write_i32 (old name)
  • C++: Buf::write_i32(int32_t v) → Expected<void>; clight::net::buf_write_i32(cl_buf b, int32_t v) → Expected<void>
  • Returns CL_OK or an error code (Error codes). Lua raises a cl.Error on failure.

cl_buf_write_i64

cl_result cl_buf_write_i64(cl_buf b, int64_t v);
  • Side: both. Context: ANY (any thread). Since: API 1.0.
  • Lua: cl.buf.write_i64, buf:write_i64(...), cl.net.buf_write_i64 (old name)
  • C++: Buf::write_i64(int64_t v) → Expected<void>; clight::net::buf_write_i64(cl_buf b, int64_t v) → Expected<void>
  • Returns CL_OK or an error code (Error codes). Lua raises a cl.Error on failure.

cl_buf_write_f32

cl_result cl_buf_write_f32(cl_buf b, float v);
  • Side: both. Context: ANY (any thread). Since: API 1.0.
  • Lua: cl.buf.write_f32, buf:write_f32(...), cl.net.buf_write_f32 (old name)
  • C++: Buf::write_f32(float v) → Expected<void>; clight::net::buf_write_f32(cl_buf b, float v) → Expected<void>
  • Returns CL_OK or an error code (Error codes). Lua raises a cl.Error on failure.

cl_buf_write_f64

cl_result cl_buf_write_f64(cl_buf b, double v);
  • Side: both. Context: ANY (any thread). Since: API 1.0.
  • Lua: cl.buf.write_f64, buf:write_f64(...), cl.net.buf_write_f64 (old name)
  • C++: Buf::write_f64(double v) → Expected<void>; clight::net::buf_write_f64(cl_buf b, double v) → Expected<void>
  • Returns CL_OK or an error code (Error codes). Lua raises a cl.Error on failure.

cl_buf_write_str

cl_result cl_buf_write_str(cl_buf b, cl_str s);
  • Side: both. Context: ANY (any thread). Since: API 1.0.
  • Lua: cl.buf.write_str, buf:write_str(...), cl.net.buf_write_str (old name)
  • C++: Buf::write_str(std::string_view s) → Expected<void>; clight::net::buf_write_str(cl_buf b, std::string_view s) → Expected<void>
  • Returns CL_OK or an error code (Error codes). Lua raises a cl.Error on failure.

cl_buf_read_varint

cl_result cl_buf_read_varint(cl_buf b, int32_t* out);
  • Side: both. Context: ANY (any thread). Since: API 1.0.
  • Lua: cl.buf.read_varint, buf:read_varint(...), cl.net.buf_read_varint (old name)
  • C++: Buf::read_varint() → Expected<int32_t>; clight::net::buf_read_varint(cl_buf b) → Expected<int32_t>
  • The last parameter receives the result. Lua returns it; C++ returns it in Expected<T>.
  • Returns CL_OK or an error code (Error codes). Lua raises a cl.Error on failure.

cl_buf_read_i32

cl_result cl_buf_read_i32(cl_buf b, int32_t* out);
  • Side: both. Context: ANY (any thread). Since: API 1.0.
  • Lua: cl.buf.read_i32, buf:read_i32(...), cl.net.buf_read_i32 (old name)
  • C++: Buf::read_i32() → Expected<int32_t>; clight::net::buf_read_i32(cl_buf b) → Expected<int32_t>
  • The last parameter receives the result. Lua returns it; C++ returns it in Expected<T>.
  • Returns CL_OK or an error code (Error codes). Lua raises a cl.Error on failure.

cl_buf_read_i64

cl_result cl_buf_read_i64(cl_buf b, int64_t* out);
  • Side: both. Context: ANY (any thread). Since: API 1.0.
  • Lua: cl.buf.read_i64, buf:read_i64(...), cl.net.buf_read_i64 (old name)
  • C++: Buf::read_i64() → Expected<int64_t>; clight::net::buf_read_i64(cl_buf b) → Expected<int64_t>
  • The last parameter receives the result. Lua returns it; C++ returns it in Expected<T>.
  • Returns CL_OK or an error code (Error codes). Lua raises a cl.Error on failure.

cl_buf_read_f32

cl_result cl_buf_read_f32(cl_buf b, float* out);
  • Side: both. Context: ANY (any thread). Since: API 1.0.
  • Lua: cl.buf.read_f32, buf:read_f32(...), cl.net.buf_read_f32 (old name)
  • C++: Buf::read_f32() → Expected<float>; clight::net::buf_read_f32(cl_buf b) → Expected<float>
  • The last parameter receives the result. Lua returns it; C++ returns it in Expected<T>.
  • Returns CL_OK or an error code (Error codes). Lua raises a cl.Error on failure.

cl_buf_read_f64

cl_result cl_buf_read_f64(cl_buf b, double* out);
  • Side: both. Context: ANY (any thread). Since: API 1.0.
  • Lua: cl.buf.read_f64, buf:read_f64(...), cl.net.buf_read_f64 (old name)
  • C++: Buf::read_f64() → Expected<double>; clight::net::buf_read_f64(cl_buf b) → Expected<double>
  • The last parameter receives the result. Lua returns it; C++ returns it in Expected<T>.
  • Returns CL_OK or an error code (Error codes). Lua raises a cl.Error on failure.

cl_buf_read_str

cl_result cl_buf_read_str(cl_buf b, char* buf, size_t cap, size_t* out_len);
  • Side: both. Context: ANY (any thread). Since: API 1.0.
  • Lua: cl.buf.read_str, buf:read_str(...), cl.net.buf_read_str (old name)
  • C++: Buf::read_str() → Expected<std::string>; clight::net::buf_read_str(cl_buf b) → Expected<std::string>
  • Writes a string: buf / cap / out_len (a too small buffer returns CL_E_BUFFER_TOO_SMALL with the needed length in *out_len). Lua and C++ return the string.
  • Returns CL_OK or an error code (Error codes). Lua raises a cl.Error on failure.

cl_buf_remaining

size_t cl_buf_remaining(cl_buf b);
  • Side: both. Context: ANY (any thread). Since: API 1.0.
  • Lua: cl.buf.remaining, buf:remaining(...), cl.net.buf_remaining (old name)
  • C++: Buf::remaining() → size_t; clight::net::buf_remaining(cl_buf b) → size_t