Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/core/chuck_dl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,59 @@ t_CKINT CK_DLL_CALL ck_get_vtable_offset( Chuck_VM * vm, Chuck_Type * t, const c
}



//-----------------------------------------------------------------------------
// name: ck_get_vtable_offset_args()
// desc: function pointer get_type(), searching for function defintion with
// specific args | 1.5.5.9 (nshaheed) added
//-----------------------------------------------------------------------------
t_CKINT CK_DLL_CALL ck_get_vtable_offset_args( Chuck_VM * vm, Chuck_Type * t, const char * valueName, Chuck_Type ** args, int num_args )
{
// find the offset for value by name
Chuck_Value * value = type_engine_find_value( t, valueName );
// value not found
if( !value || !value->func_ref ) return -1;

Chuck_Func * func = value->func_ref;

// iterate over overloads looking for matching number of args and types
while (func) {
a_Func_Def func_def = func->def();
a_Arg_List arg_list = func_def->arg_list;

bool type_signature_match = true;
int i = 0;

// size of arg lists must match
while( arg_list && i < num_args ) {
// types do not match, exit loop
if (!isa(args[i], arg_list->type)) {
type_signature_match = false;
break;
}

arg_list = arg_list->next;
i++;
}

// expected more args from func
if (i != num_args) type_signature_match = false;
// func had too many args
if (arg_list) type_signature_match = false;

// found a match! returning offset...
if (type_signature_match) {
return func->vt_index;
}
func = func->next;
}

// was not able to find a match, returning -1
return -1;
}



//-----------------------------------------------------------------------------
// add reference count
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -2818,6 +2871,7 @@ array_vec4_clear( ck_array_vec4_clear )
Chuck_DL_Api::TypeApi::TypeApi() :
lookup(ck_type_lookup),
get_vtable_offset(ck_get_vtable_offset),
get_vtable_offset_args(ck_get_vtable_offset_args),
is_equal(ck_type_isequal),
isa(ck_type_isa),
callback_on_instantiate(ck_callback_on_instantiate),
Expand Down
2 changes: 2 additions & 0 deletions src/core/chuck_dl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,8 @@ struct Chuck_DL_Api
Type (CK_DLL_CALL * const lookup)( Chuck_VM *, const char * name );
// get vtable offset for named function (if overloaded, returns first one); returns < 0 if not found
t_CKINT (CK_DLL_CALL * const get_vtable_offset)( Chuck_VM *, Type type, const char * funcName );
// get vtable offset for named function with specific input arguments (if overloaded, returns first one); returns < 0 if not found
t_CKINT (CK_DLL_CALL * const get_vtable_offset_args)( Chuck_VM *, Type type, const char * funcName, Type * args, int num_args);
// test if two chuck types are equal
t_CKBOOL (CK_DLL_CALL * const is_equal)(Type lhs, Type rhs);
// test if lhs is a type of rhs (e.g., SinOsc is a type of UGen)
Expand Down
Loading