/* Convert argument to C pointer. */ static void *ffi_checkptr(lua_State *L, int narg, CTypeID id) { CTState *cts = ctype_cts(L); TValue *o = L->base + narg-1; void *p; if (o >= L->top) lj_err_arg(L, narg, LJ_ERR_NOVAL); lj_cconv_ct_tv(cts, ctype_get(cts, id), (uint8_t *)&p, o, CCF_ARG(narg)); return p; }
/* Convert argument to int32_t. */ static int32_t ffi_checkint(lua_State *L, int narg) { CTState *cts = ctype_cts(L); TValue *o = L->base + narg-1; int32_t i; if (o >= L->top) lj_err_arg(L, narg, LJ_ERR_NOVAL); lj_cconv_ct_tv(cts, ctype_get(cts, CTID_INT32), (uint8_t *)&i, o, CCF_ARG(narg)); return i; }
/* Pass a small struct argument. */ static int ccall_struct_arg(CCallState *cc, CTState *cts, CType *d, int *rcl, TValue *o, int narg) { GPRArg dp[2]; dp[0] = dp[1] = 0; /* Convert to temp. struct. */ lj_cconv_ct_tv(cts, d, (uint8_t *)dp, o, CCF_ARG(narg)); if (ccall_struct_reg(cc, dp, rcl)) { /* Register overflow? Pass on stack. */ MSize nsp = cc->nsp, n = rcl[1] ? 2 : 1; if (nsp + n > CCALL_MAXSTACK) return 1; /* Too many arguments. */ cc->nsp = nsp + n; memcpy(&cc->stack[nsp], dp, n*CTSIZE_PTR); } return 0; /* Ok. */ }