You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.8 KiB

/******************************************************************************
版权所有 (C), 2018-2099, Radkil
******************************************************************************
文 件 名 : pb_lua.h
版 本 号 : 初稿
功 能 描 述 : nanopb 消息的 Lua 序列化/反序列化桥接接口
******************************************************************************/
#ifndef __PB_LUA_H__
#define __PB_LUA_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifdef BUILD_PROTOBUF
#include "lua.h"
/*
* Lua 全局函数(由 lacmd.c 的 luaopen_default 注册):
* pb_encode("TPokemonPV", t) -> binary string
* pb_decode("TPokemonPV", bin) -> table
* pb_dump("TPokemonPV", bin|table) -- pretty print
* pb_new("TPokemonPV") -> zero-filled table (fill & encode)
* pb_ref("CV") -> live userdata view of a bound C global
* p.Field / p.Field = v -- read/write through to C memory
* p.Sub.Field = 10 -- 嵌套 MESSAGE: Mutable 语义, 首次进入置 has_
* p:dump() / p:encode() / p:totable()
*
* C 函数名带 l_ 前缀,避开 nanopb 导出的 pb_encode/pb_decode 符号。
*/
int l_pb_encode(lua_State *L);
int l_pb_decode(lua_State *L);
int l_pb_dump(lua_State *L);
int l_pb_new(lua_State *L);
int l_pb_ref(lua_State *L);
/* C 侧注册 API:把命名指针绑定到消息类型名(按 type name 查描述符)。
* 幂等:同名重复绑定更新指针。0=OK, -1=未知类型, -2=注册表满。
* 供业务模块在自身初始化处调用,不依赖 lua_State。 */
int pb_lua_bind(const char *name, void *ptr, const char *msgtype);
/* 每个 lua_State 一次(luaopen_default 调用):
* 创建 PB_LIVE metatable + 绑定 demo 全局 g_pokemon_pv。幂等。 */
void pb_lua_open(lua_State *L);
#endif
#ifdef __cplusplus
}
#endif
#endif /* __PB_LUA_H__ */