Classes | Macros | Enumerations | Functions | Variables
bindings/lua/msg.c File Reference
#include "upb/msg.h"
#include <float.h>
#include <math.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "lauxlib.h"
#include "upb/bindings/lua/upb.h"
#include "upb/json_decode.h"
#include "upb/json_encode.h"
#include "upb/port_def.inc"
#include "upb/reflection.h"
#include "upb/text_encode.h"
Include dependency graph for bindings/lua/msg.c:

Go to the source code of this file.

Classes

struct  lupb_Arena
 
struct  lupb_array
 
struct  lupb_map
 
struct  lupb_Message
 

Macros

#define LUPB_ARENA   "lupb.arena"
 
#define LUPB_ARENA_INDEX   1
 
#define LUPB_ARRAY   "lupb.array"
 
#define LUPB_MAP   "lupb.map"
 
#define LUPB_MSG   "lupb.msg"
 
#define LUPB_MSGDEF_INDEX   2 /* For msg, and map/array that store msg */
 
#define MAP_MSGDEF_INDEX   1
 

Enumerations

enum  lupb_copy_t { LUPB_COPY, LUPB_REF }
 

Functions

static upb_Arenalupb_Arena_check (lua_State *L, int narg)
 
static void lupb_Arena_Fuse (lua_State *L, int to, int from)
 
static void lupb_Arena_Fuseobjs (lua_State *L, int to, int from)
 
static int lupb_Arena_gc (lua_State *L)
 
upb_Arenalupb_Arena_pushnew (lua_State *L)
 
static upb_Arenalupb_Arenaget (lua_State *L, int narg)
 
static lupb_arraylupb_array_check (lua_State *L, int narg)
 
static int lupb_array_checkindex (lua_State *L, int narg, uint32_t max)
 
static int lupb_array_index (lua_State *L)
 
static int lupb_array_len (lua_State *L)
 
static int lupb_Array_New (lua_State *L)
 
static int lupb_Array_Newindex (lua_State *L)
 
static bool lupb_cacheget (lua_State *L, const void *key)
 
static void lupb_cacheinit (lua_State *L)
 
static void lupb_cacheset (lua_State *L, const void *key)
 
static upb_CType lupb_checkfieldtype (lua_State *L, int narg)
 
static int lupb_decode (lua_State *L)
 
static int lupb_Encode (lua_State *L)
 
static int lupb_getoptions (lua_State *L, int narg)
 
static int lupb_jsondecode (lua_State *L)
 
static int lupb_jsonencode (lua_State *L)
 
static lupb_maplupb_map_check (lua_State *L, int narg)
 
static int lupb_map_index (lua_State *L)
 
static int lupb_map_len (lua_State *L)
 
static int lupb_Map_New (lua_State *L)
 
static int lupb_Map_Newindex (lua_State *L)
 
static int lupb_map_pairs (lua_State *L)
 
static int lupb_MapIterator_Next (lua_State *L)
 
static const upb_MessageDeflupb_Message_Getmsgdef (lua_State *L, int msg)
 
static int lupb_Message_Newindex (lua_State *L)
 
static void lupb_Message_Newmsgwrapper (lua_State *L, int narg, upb_MessageValue val)
 
static void * lupb_Message_Newud (lua_State *L, int narg, size_t size, const char *type, const upb_FieldDef *f)
 
static void lupb_Message_Newwrapper (lua_State *L, int narg, const upb_FieldDef *f, upb_MutableMessageValue val)
 
int lupb_MessageDef_call (lua_State *L)
 
static upb_Messagelupb_msg_check (lua_State *L, int narg)
 
static const upb_FieldDeflupb_msg_checkfield (lua_State *L, int msg, int field)
 
static int lupb_msg_index (lua_State *L)
 
upb_Messagelupb_msg_pushnew (lua_State *L, int narg)
 
void lupb_msg_registertypes (lua_State *L)
 
static const upb_FieldDeflupb_msg_tofield (lua_State *L, int msg, int field)
 
static int lupb_msg_tostring (lua_State *L)
 
static void lupb_msg_typechecksubmsg (lua_State *L, int narg, int msgarg, const upb_FieldDef *f)
 
void lupb_pushmsgval (lua_State *L, int container, upb_CType type, upb_MessageValue val)
 
static void lupb_setfieldi (lua_State *L, const char *field, int i)
 
static int lupb_textencode (lua_State *L)
 
static upb_MessageValue lupb_tomsgval (lua_State *L, upb_CType type, int narg, int container, lupb_copy_t copy)
 

Variables

char cache_key
 
static const struct luaL_Reg lupb_Arena_mm []
 
static const struct luaL_Reg lupb_array_mm []
 
static const struct luaL_Reg lupb_map_mm []
 
static const struct luaL_Reg lupb_msg_mm []
 
static const struct luaL_Reg lupb_msg_toplevel_m []
 

Macro Definition Documentation

◆ LUPB_ARENA

#define LUPB_ARENA   "lupb.arena"

Definition at line 113 of file bindings/lua/msg.c.

◆ LUPB_ARENA_INDEX

#define LUPB_ARENA_INDEX   1

Definition at line 118 of file bindings/lua/msg.c.

◆ LUPB_ARRAY

#define LUPB_ARRAY   "lupb.array"

Definition at line 114 of file bindings/lua/msg.c.

◆ LUPB_MAP

#define LUPB_MAP   "lupb.map"

Definition at line 115 of file bindings/lua/msg.c.

◆ LUPB_MSG

#define LUPB_MSG   "lupb.msg"

Definition at line 116 of file bindings/lua/msg.c.

◆ LUPB_MSGDEF_INDEX

#define LUPB_MSGDEF_INDEX   2 /* For msg, and map/array that store msg */

Definition at line 119 of file bindings/lua/msg.c.

◆ MAP_MSGDEF_INDEX

#define MAP_MSGDEF_INDEX   1

Definition at line 496 of file bindings/lua/msg.c.

Enumeration Type Documentation

◆ lupb_copy_t

Enumerator
LUPB_COPY 
LUPB_REF 

Definition at line 253 of file bindings/lua/msg.c.

Function Documentation

◆ lupb_Arena_check()

static upb_Arena* lupb_Arena_check ( lua_State *  L,
int  narg 
)
static

Definition at line 197 of file bindings/lua/msg.c.

◆ lupb_Arena_Fuse()

static void lupb_Arena_Fuse ( lua_State *  L,
int  to,
int  from 
)
static

lupb_Arena_Fuse()

Merges |from| into |to| so that there is a single arena group that contains both, and both arenas will point at this new table.

Definition at line 213 of file bindings/lua/msg.c.

◆ lupb_Arena_Fuseobjs()

static void lupb_Arena_Fuseobjs ( lua_State *  L,
int  to,
int  from 
)
static

Definition at line 219 of file bindings/lua/msg.c.

◆ lupb_Arena_gc()

static int lupb_Arena_gc ( lua_State *  L)
static

Definition at line 226 of file bindings/lua/msg.c.

◆ lupb_Arena_pushnew()

upb_Arena* lupb_Arena_pushnew ( lua_State *  L)

Definition at line 202 of file bindings/lua/msg.c.

◆ lupb_Arenaget()

static upb_Arena* lupb_Arenaget ( lua_State *  L,
int  narg 
)
static

Definition at line 239 of file bindings/lua/msg.c.

◆ lupb_array_check()

static lupb_array* lupb_array_check ( lua_State *  L,
int  narg 
)
static

Definition at line 365 of file bindings/lua/msg.c.

◆ lupb_array_checkindex()

static int lupb_array_checkindex ( lua_State *  L,
int  narg,
uint32_t  max 
)
static

lupb_array_checkindex()

Checks the array index at Lua stack index |narg| to verify that it is an integer between 1 and |max|, inclusively. Also corrects it to be zero-based for C.

Definition at line 376 of file bindings/lua/msg.c.

◆ lupb_array_index()

static int lupb_array_index ( lua_State *  L)
static

Definition at line 460 of file bindings/lua/msg.c.

◆ lupb_array_len()

static int lupb_array_len ( lua_State *  L)
static

Definition at line 476 of file bindings/lua/msg.c.

◆ lupb_Array_New()

static int lupb_Array_New ( lua_State *  L)
static

Definition at line 390 of file bindings/lua/msg.c.

◆ lupb_Array_Newindex()

static int lupb_Array_Newindex ( lua_State *  L)
static

Definition at line 434 of file bindings/lua/msg.c.

◆ lupb_cacheget()

static bool lupb_cacheget ( lua_State *  L,
const void *  key 
)
static

Definition at line 157 of file bindings/lua/msg.c.

◆ lupb_cacheinit()

static void lupb_cacheinit ( lua_State *  L)
static

Definition at line 138 of file bindings/lua/msg.c.

◆ lupb_cacheset()

static void lupb_cacheset ( lua_State *  L,
const void *  key 
)
static

Definition at line 179 of file bindings/lua/msg.c.

◆ lupb_checkfieldtype()

static upb_CType lupb_checkfieldtype ( lua_State *  L,
int  narg 
)
static

Definition at line 125 of file bindings/lua/msg.c.

◆ lupb_decode()

static int lupb_decode ( lua_State *  L)
static

lupb_decode()

Handles: msg = upb.decode(MessageClass, bin_string)

Definition at line 951 of file bindings/lua/msg.c.

◆ lupb_Encode()

static int lupb_Encode ( lua_State *  L)
static

lupb_Encode()

Handles: bin_string = upb.encode(msg)

Definition at line 981 of file bindings/lua/msg.c.

◆ lupb_getoptions()

static int lupb_getoptions ( lua_State *  L,
int  narg 
)
static

Definition at line 932 of file bindings/lua/msg.c.

◆ lupb_jsondecode()

static int lupb_jsondecode ( lua_State *  L)
static

lupb_jsondecode()

Handles: text_string = upb.json_decode(MessageClass, json_str, {upb.JSONDEC_IGNOREUNKNOWN})

Definition at line 1010 of file bindings/lua/msg.c.

◆ lupb_jsonencode()

static int lupb_jsonencode ( lua_State *  L)
static

lupb_jsonencode()

Handles: text_string = upb.json_encode(msg, {upb.JSONENC_EMITDEFAULTS})

Definition at line 1034 of file bindings/lua/msg.c.

◆ lupb_map_check()

static lupb_map* lupb_map_check ( lua_State *  L,
int  narg 
)
static

Definition at line 498 of file bindings/lua/msg.c.

◆ lupb_map_index()

static int lupb_map_index ( lua_State *  L)
static

lupb_map_index

Handles: map[key]

Definition at line 542 of file bindings/lua/msg.c.

◆ lupb_map_len()

static int lupb_map_len ( lua_State *  L)
static

lupb_map_len

Handles: map_len = map

Definition at line 562 of file bindings/lua/msg.c.

◆ lupb_Map_New()

static int lupb_Map_New ( lua_State *  L)
static

lupb_Map_New

Handles: new_map = upb.Map(key_type, value_type) new_map = upb.Map(key_type, value_msgdef)

Definition at line 511 of file bindings/lua/msg.c.

◆ lupb_Map_Newindex()

static int lupb_Map_Newindex ( lua_State *  L)
static

lupb_Map_Newindex

Handles: map[key] = val map[key] = nil # to remove from map

Definition at line 575 of file bindings/lua/msg.c.

◆ lupb_map_pairs()

static int lupb_map_pairs ( lua_State *  L)
static

lupb_map_pairs()

Handles: pairs(map)

Definition at line 615 of file bindings/lua/msg.c.

◆ lupb_MapIterator_Next()

static int lupb_MapIterator_Next ( lua_State *  L)
static

Definition at line 593 of file bindings/lua/msg.c.

◆ lupb_Message_Getmsgdef()

static const upb_MessageDef* lupb_Message_Getmsgdef ( lua_State *  L,
int  msg 
)
static

Definition at line 650 of file bindings/lua/msg.c.

◆ lupb_Message_Newindex()

static int lupb_Message_Newindex ( lua_State *  L)
static

lupb_Message_Newindex()

Handles: msg.foo = bar msg["foo"] = bar msg[field_descriptor] = bar # (for extensions) (TODO)

Definition at line 843 of file bindings/lua/msg.c.

◆ lupb_Message_Newmsgwrapper()

static void lupb_Message_Newmsgwrapper ( lua_State *  L,
int  narg,
upb_MessageValue  val 
)
static

lupb_Message_Newmsgwrapper()

Creates a new wrapper for a message, copying the arena and msgdef references from |narg| (which should be an array or map).

Definition at line 693 of file bindings/lua/msg.c.

◆ lupb_Message_Newud()

static void* lupb_Message_Newud ( lua_State *  L,
int  narg,
size_t  size,
const char *  type,
const upb_FieldDef f 
)
static

lupb_Message_Newud()

Creates the Lua userdata for a new wrapper object, adding a reference to the msgdef if necessary.

Definition at line 712 of file bindings/lua/msg.c.

◆ lupb_Message_Newwrapper()

static void lupb_Message_Newwrapper ( lua_State *  L,
int  narg,
const upb_FieldDef f,
upb_MutableMessageValue  val 
)
static

lupb_Message_Newwrapper()

Creates a new Lua wrapper object to wrap the given array, map, or message.

Definition at line 731 of file bindings/lua/msg.c.

◆ lupb_MessageDef_call()

int lupb_MessageDef_call ( lua_State *  L)

lupb_MessageDef_call

Handles: new_msg = MessageClass() new_msg = MessageClass{foo = "bar", baz = 3, quux = {foo = 3}}

Definition at line 789 of file bindings/lua/msg.c.

◆ lupb_msg_check()

static upb_Message * lupb_msg_check ( lua_State *  L,
int  narg 
)
static

Definition at line 645 of file bindings/lua/msg.c.

◆ lupb_msg_checkfield()

static const upb_FieldDef* lupb_msg_checkfield ( lua_State *  L,
int  msg,
int  field 
)
static

Definition at line 664 of file bindings/lua/msg.c.

◆ lupb_msg_index()

static int lupb_msg_index ( lua_State *  L)
static

lupb_msg_index

Handles: msg.foo msg["foo"] msg[field_descriptor] # (for extensions) (TODO)

Definition at line 815 of file bindings/lua/msg.c.

◆ lupb_msg_pushnew()

upb_Message* lupb_msg_pushnew ( lua_State *  L,
int  narg 
)

Definition at line 673 of file bindings/lua/msg.c.

◆ lupb_msg_registertypes()

void lupb_msg_registertypes ( lua_State *  L)

Definition at line 1097 of file bindings/lua/msg.c.

◆ lupb_msg_tofield()

static const upb_FieldDef* lupb_msg_tofield ( lua_State *  L,
int  msg,
int  field 
)
static

Definition at line 657 of file bindings/lua/msg.c.

◆ lupb_msg_tostring()

static int lupb_msg_tostring ( lua_State *  L)
static

lupb_msg_tostring()

Handles: tostring(msg) print(msg) etc.

Definition at line 900 of file bindings/lua/msg.c.

◆ lupb_msg_typechecksubmsg()

static void lupb_msg_typechecksubmsg ( lua_State *  L,
int  narg,
int  msgarg,
const upb_FieldDef f 
)
static

lupb_msg_typechecksubmsg()

Typechecks the given array, map, or msg against this upb_FieldDef.

Definition at line 770 of file bindings/lua/msg.c.

◆ lupb_pushmsgval()

void lupb_pushmsgval ( lua_State *  L,
int  container,
upb_CType  type,
upb_MessageValue  val 
)

From msg.c.

Definition at line 319 of file bindings/lua/msg.c.

◆ lupb_setfieldi()

static void lupb_setfieldi ( lua_State *  L,
const char *  field,
int  i 
)
static

Definition at line 1086 of file bindings/lua/msg.c.

◆ lupb_textencode()

static int lupb_textencode ( lua_State *  L)
static

lupb_textencode()

Handles: text_string = upb.text_encode(msg, {upb.TXTENC_SINGLELINE})

Definition at line 1065 of file bindings/lua/msg.c.

◆ lupb_tomsgval()

static upb_MessageValue lupb_tomsgval ( lua_State *  L,
upb_CType  type,
int  narg,
int  container,
lupb_copy_t  copy 
)
static

lupb_tomsgval()

Converts the given Lua value |narg| to a upb_MessageValue.

Definition at line 263 of file bindings/lua/msg.c.

Variable Documentation

◆ cache_key

char cache_key

Definition at line 132 of file bindings/lua/msg.c.

◆ lupb_Arena_mm

const struct luaL_Reg lupb_Arena_mm[]
static
Initial value:
= {{"__gc", lupb_Arena_gc},
{NULL, NULL}}

Definition at line 232 of file bindings/lua/msg.c.

◆ lupb_array_mm

const struct luaL_Reg lupb_array_mm[]
static
Initial value:
= {
{"__index", lupb_array_index},
{"__len", lupb_array_len},
{"__newindex", lupb_Array_Newindex},
{NULL, NULL}}

Definition at line 482 of file bindings/lua/msg.c.

◆ lupb_map_mm

const struct luaL_Reg lupb_map_mm[]
static
Initial value:
= {{"__index", lupb_map_index},
{"__len", lupb_map_len},
{"__newindex", lupb_Map_Newindex},
{"__pairs", lupb_map_pairs},
{NULL, NULL}}

Definition at line 630 of file bindings/lua/msg.c.

◆ lupb_msg_mm

const struct luaL_Reg lupb_msg_mm[]
static
Initial value:
= {
{"__index", lupb_msg_index},
{"__newindex", lupb_Message_Newindex},
{"__tostring", lupb_msg_tostring},
{NULL, NULL}}

Definition at line 923 of file bindings/lua/msg.c.

◆ lupb_msg_toplevel_m

const struct luaL_Reg lupb_msg_toplevel_m[]
static
Initial value:
= {
{"Array", lupb_Array_New}, {"Map", lupb_Map_New},
{"decode", lupb_decode}, {"encode", lupb_Encode},
{"json_decode", lupb_jsondecode}, {"json_encode", lupb_jsonencode},
{"text_encode", lupb_textencode}, {NULL, NULL}}

Definition at line 1091 of file bindings/lua/msg.c.

lupb_Map_New
static int lupb_Map_New(lua_State *L)
Definition: bindings/lua/msg.c:511
lupb_Arena_gc
static int lupb_Arena_gc(lua_State *L)
Definition: bindings/lua/msg.c:226
lupb_textencode
static int lupb_textencode(lua_State *L)
Definition: bindings/lua/msg.c:1065
lupb_Array_New
static int lupb_Array_New(lua_State *L)
Definition: bindings/lua/msg.c:390
lupb_decode
static int lupb_decode(lua_State *L)
Definition: bindings/lua/msg.c:951
lupb_map_index
static int lupb_map_index(lua_State *L)
Definition: bindings/lua/msg.c:542
lupb_jsonencode
static int lupb_jsonencode(lua_State *L)
Definition: bindings/lua/msg.c:1034
lupb_msg_tostring
static int lupb_msg_tostring(lua_State *L)
Definition: bindings/lua/msg.c:900
lupb_Array_Newindex
static int lupb_Array_Newindex(lua_State *L)
Definition: bindings/lua/msg.c:434
lupb_Map_Newindex
static int lupb_Map_Newindex(lua_State *L)
Definition: bindings/lua/msg.c:575
lupb_Message_Newindex
static int lupb_Message_Newindex(lua_State *L)
Definition: bindings/lua/msg.c:843
lupb_Encode
static int lupb_Encode(lua_State *L)
Definition: bindings/lua/msg.c:981
lupb_msg_index
static int lupb_msg_index(lua_State *L)
Definition: bindings/lua/msg.c:815
lupb_map_len
static int lupb_map_len(lua_State *L)
Definition: bindings/lua/msg.c:562
lupb_map_pairs
static int lupb_map_pairs(lua_State *L)
Definition: bindings/lua/msg.c:615
lupb_array_index
static int lupb_array_index(lua_State *L)
Definition: bindings/lua/msg.c:460
lupb_jsondecode
static int lupb_jsondecode(lua_State *L)
Definition: bindings/lua/msg.c:1010
lupb_array_len
static int lupb_array_len(lua_State *L)
Definition: bindings/lua/msg.c:476


grpc
Author(s):
autogenerated on Fri May 16 2025 03:01:23