static timer_lua_t *timer_lua_check(lua_State *L, int idx) { return (timer_lua_t *)mrp_lua_check_object(L, TIMER_LUA_CLASS, idx); }
static inline resource_lua_t *resource_lua_check(lua_State *L, int idx) { return (resource_lua_t *) mrp_lua_check_object(L, RESOURCE_LUA_CLASS, idx); }
static inline attribute_lua_t *attribute_lua_check(lua_State *L, int idx) { return (attribute_lua_t *) mrp_lua_check_object(L, ATTRIBUTE_LUA_CLASS, idx); }
static int make_lua_call(lua_State *L, mrp_funcbridge_t *fb, int f) { #define ARG_MAX 256 int ret; int i, n, m, b, e; const char *s; char t; mrp_funcbridge_value_t args[ARG_MAX]; mrp_funcbridge_value_t *a, r; e = lua_gettop(L); f = (f < 0) ? e + f + 1 : f; b = f + 1; n = e - b + 1; switch (fb->type) { case MRP_C_FUNCTION: m = strlen(fb->c.signature); if (n >= ARG_MAX - 1 || n > m) return luaL_error(L, "too many arguments"); if (n < m) return luaL_error(L, "too few arguments"); for (i = b, s = fb->c.signature, a= args; i <= e; i++, s++, a++){ switch (*s) { case MRP_FUNCBRIDGE_STRING: a->string = luaL_checklstring(L, i, NULL); break; case MRP_FUNCBRIDGE_INTEGER: a->integer = luaL_checkinteger(L, i); break; case MRP_FUNCBRIDGE_FLOATING: a->floating = luaL_checknumber(L, i); break; case MRP_FUNCBRIDGE_OBJECT: a->pointer = mrp_lua_check_object(L, NULL, i); break; default: return luaL_error(L, "argument %d has unsupported type '%c'", (i - b) + 1, i); } } memset(a, 0, sizeof(*a)); if (!fb->c.func(L, fb->c.data, fb->c.signature, args, &t, &r)) return luaL_error(L, "c function invocation failed"); switch (t) { case MRP_FUNCBRIDGE_NO_DATA: ret = 0; break; case MRP_FUNCBRIDGE_STRING: ret = 1; lua_pushstring(L, r.string); break; case MRP_FUNCBRIDGE_INTEGER: ret = 1; lua_pushinteger(L, r.integer); break; case MRP_FUNCBRIDGE_FLOATING: ret = 1; lua_pushnumber(L, r.floating); break; default: ret = 0; lua_pushnil(L); } break; case MRP_LUA_FUNCTION: lua_rawgeti(L, f, 1); luaL_checktype(L, -1, LUA_TFUNCTION); lua_replace(L, f); lua_pcall(L, n, 1, 0); ret = 1; break; default: return luaL_error(L, "internal error"); } return ret; #undef ARG_MAX }