Skip to content

added get_vtable_offset_args to chugin api#552

Open
nshaheed wants to merge 1 commit into
ccrma:mainfrom
nshaheed:vt_offset_args
Open

added get_vtable_offset_args to chugin api#552
nshaheed wants to merge 1 commit into
ccrma:mainfrom
nshaheed:vt_offset_args

Conversation

@nshaheed

@nshaheed nshaheed commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

This lets you find a function definition with a specific argument list (i.e. now you can look for SinOsc.freq() when SinOsc.freq(float f) is the first in the overload list of SinOsc.freq.

Here's an example usage:

// Call getter function
CK_DLL_SFUN(patch_call) {
  Chuck_Object* obj = (Chuck_Object*)GET_NEXT_OBJECT(ARGS);
  Chuck_String *method = (Chuck_String *)GET_NEXT_STRING(ARGS);

  // Get object to find offset from
  Chuck_DL_Api::Type obj_type = API->object->get_type( obj );
  Chuck_Type * t = (Chuck_Type *)obj_type;

  string method_str = API->object->str(method);

  // Want the getter, so the args list is empty
  Chuck_Type * arg_list[] = {};
  
  // Lookup the specific function definition, normally this would return the setter
  t_CKINT offset =
    API->type->get_vtable_offset_args(VM, obj_type, method_str.c_str(), arg_list, 0);  

  if (offset < 0) {
    string message = "Member function " + method_str + "() not found in object " + string(API->type->base_name(obj_type));
    API->vm->throw_exception("MemberFunctionNotFound", message.c_str(), SHRED);
  }

  Chuck_DL_Arg* arg = new Chuck_DL_Arg();

  Chuck_DL_Return ret =
      API->vm->invoke_mfun_immediate_mode(obj, offset, VM, SHRED, arg, 0);

  RETURN->v_float = ret.v_float;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant