summaryrefslogtreecommitdiff
path: root/bindings/lua/upb.h
blob: e6b4f2fe0d0389840e350de839c1072f8f5c4792 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * upb - a minimalist implementation of protocol buffers.
 *
 * Copyright (c) 2012 Google Inc.  See LICENSE for details.
 * Author: Josh Haberman <jhaberman@gmail.com>
 *
 * Shared definitions for upb Lua modules.
 */

#ifndef UPB_LUA_UPB_H_
#define UPB_LUA_UPB_H_

#include "upb/def.h"

// Lua 5.1/5.2 compatibility code.
#if LUA_VERSION_NUM == 501

#define lua_rawlen lua_objlen
#define lupb_newlib(L, name, l) luaL_register(L, name, l)
#define lupb_setfuncs(L, l) luaL_register(L, NULL, l)
#define LUPB_OPENFUNC(mod) luaopen_ ## mod ## upb5_1

void *luaL_testudata(lua_State *L, int ud, const char *tname);

#elif LUA_VERSION_NUM == 502

// Lua 5.2 modules are not expected to set a global variable, so "name" is
// unused.
#define lupb_newlib(L, name, l) luaL_newlib(L, l)
#define lupb_setfuncs(L, l) luaL_setfuncs(L, l, 0)
int luaL_typerror(lua_State *L, int narg, const char *tname);
#define LUPB_OPENFUNC(mod) luaopen_ ## mod ## upb5_2

#else
#error Only Lua 5.1 and 5.2 are supported
#endif

const upb_msgdef *lupb_msgdef_check(lua_State *L, int narg);
const upb_enumdef *lupb_enumdef_check(lua_State *L, int narg);
const char *lupb_checkname(lua_State *L, int narg);
bool lupb_def_pushwrapper(lua_State *L, const upb_def *def, const void *owner);
void lupb_def_pushnewrapper(lua_State *L, const upb_def *def,
                            const void *owner);

#endif  // UPB_LUA_UPB_H_
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback