Debian Codegraph @

texk/web2c/luatexdir/luaharfbuzz/src/class_utils.c

raw
1 // Utility functions to create Lua classes.
2 #include "common.h"
3
4 int register_class(lua_State *L, const char *name, const luaL_Reg *methods, const luaL_Reg *functions, const luahb_constant_t *constants) {
5 luaL_newmetatable(L, name);
6 lua_pushvalue(L, -1);
7 lua_setfield(L, -2, "__index");
8
9 if (constants) {
10 while (constants->name) {
11 lua_pushinteger(L, constants->value);
12 lua_setfield(L, -2, constants->name);
13 constants++;
14 }
15 }
16
17 luaL_setfuncs(L, methods, 0);
18 lua_pop(L, 1);
19
20 lua_newtable(L);
21 luaL_setfuncs(L, functions, 0);
22
23 luaL_getmetatable(L, name);
24 lua_setmetatable(L, -2);
25 return 1;
26 }
27