static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out) { struct instance *o = vo; if (!strcmp(name, "")) { *out = ncd_make_uintmax(mem, o->value); return 1; } return 0; }
static int number_func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out) { struct number_instance *o = vo; if (name == NCD_STRING_EMPTY) { *out = ncd_make_uintmax(mem, o->value); return 1; } return 0; }
static int parse_number (NCDModuleInst *i, MemRef str, NCDValMem *mem, NCDValRef *out) { uintmax_t n; if (!parse_unsigned_integer(str, &n)) { ModuleLog(i, BLOG_ERROR, "failed to parse number"); return 0; } *out = ncd_make_uintmax(mem, n); if (NCDVal_IsInvalid(*out)) { return 0; } return 1; }
static int number_func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out) { struct number_instance *o = vo; if (name == NCD_STRING_IS_ERROR) { *out = ncd_make_boolean(mem, !!o->error, o->i->params->iparams->string_index); return 1; } if (name == NCD_STRING_EMPTY) { if (o->error) { ModuleLog(o->i, BLOG_ERROR, "%s", o->error); return 0; } *out = ncd_make_uintmax(mem, o->value); return 1; } return 0; }
static void integer_operator_eval (NCDCall call, integer_operator_func func) { if (NCDCall_ArgCount(&call) != 2) { return FunctionLog(&call, BLOG_ERROR, "integer_operator: need two arguments"); } uintmax_t ints[2]; for (int i = 0; i < 2; i++) { NCDValRef arg = NCDCall_EvalArg(&call, i, NCDCall_ResMem(&call)); if (NCDVal_IsInvalid(arg)) { return; } if (!ncd_read_uintmax(arg, &ints[i])) { return FunctionLog(&call, BLOG_ERROR, "integer_operator: wrong value"); } } uintmax_t res; if (!func(ints[0], ints[1], &res, &call)) { return; } NCDCall_SetResult(&call, ncd_make_uintmax(NCDCall_ResMem(&call), res)); }