void luaT_pushtuple(struct lua_State *L, box_tuple_t *tuple) { assert(CTID_STRUCT_TUPLE_REF != 0); struct tuple **ptr = (struct tuple **) luaL_pushcdata(L, CTID_STRUCT_TUPLE_REF); *ptr = tuple; /* The order is important - first reference tuple, next set gc */ box_tuple_ref(tuple); lua_pushcfunction(L, lbox_tuple_gc); luaL_setcdatagc(L, -2); }
static void luaL_pusherror(struct lua_State *L, struct error *e) { assert(CTID_CONST_STRUCT_ERROR_REF != 0); struct error **ptr = (struct error **) luaL_pushcdata(L, CTID_CONST_STRUCT_ERROR_REF); *ptr = e; /* The order is important - first reference the error, then set gc */ error_ref(e); lua_pushcfunction(L, luaL_error_gc); luaL_setcdatagc(L, -2); }
void luaL_pushint64(struct lua_State *L, int64_t val) { #if defined(LJ_DUALNUM) /* see setint64V() */ if (val >= INT32_MIN && val <= INT32_MAX) { /* push int32_t */ lua_pushinteger(L, (int32_t) val); } else #endif /* defined(LJ_DUALNUM) */ if (val >= DBL_INT_MIN && val <= DBL_INT_MAX) { /* push double */ lua_pushnumber(L, (double) val); } else { /* push int64_t */ *(int64_t *) luaL_pushcdata(L, CTID_INT64) = val; } }
int tarantool_lua_utils_init(struct lua_State *L) { static const struct luaL_reg serializermeta[] = { {NULL, NULL}, }; /* Get CTypeID for `struct error *' */ int rc = luaL_cdef(L, "struct error;"); assert(rc == 0); (void) rc; CTID_CONST_STRUCT_ERROR_REF = luaL_ctypeid(L, "const struct error &"); assert(CTID_CONST_STRUCT_ERROR_REF != 0); luaL_register_type(L, LUAL_SERIALIZER, serializermeta); /* Create NULL constant */ *(void **) luaL_pushcdata(L, CTID_P_VOID) = NULL; luaL_nil_ref = luaL_ref(L, LUA_REGISTRYINDEX); lua_createtable(L, 0, 1); lua_pushliteral(L, "map"); /* YAML will use flow mode */ lua_setfield(L, -2, LUAL_SERIALIZE); /* automatically reset hints on table change */ luaL_loadstring(L, "setmetatable((...), nil); return rawset(...)"); lua_setfield(L, -2, "__newindex"); luaL_map_metatable_ref = luaL_ref(L, LUA_REGISTRYINDEX); lua_createtable(L, 0, 1); lua_pushliteral(L, "seq"); /* YAML will use flow mode */ lua_setfield(L, -2, LUAL_SERIALIZE); /* automatically reset hints on table change */ luaL_loadstring(L, "setmetatable((...), nil); return rawset(...)"); lua_setfield(L, -2, "__newindex"); luaL_array_metatable_ref = luaL_ref(L, LUA_REGISTRYINDEX); fpconv_init(); return 0; }