Skip to content

Commit

Permalink
extern: Pass full callable value to external function callback
Browse files Browse the repository at this point in the history
  • Loading branch information
obiwac committed Oct 29, 2024
1 parent b51ac0a commit 76b6ece
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion flamingo/call.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static int call_with_set_args_cb(

assert(flamingo->cur_fn_rv == NULL);

if (is_extern && flamingo->external_fn_cb(flamingo, callable->name_size, callable->name, flamingo->external_fn_cb_data, &arg_list, &flamingo->cur_fn_rv) < 0) {
if (is_extern && flamingo->external_fn_cb(flamingo, callable, flamingo->external_fn_cb_data, &arg_list, &flamingo->cur_fn_rv) < 0) {
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion flamingo/flamingo.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ typedef struct flamingo_scope_t flamingo_scope_t;
typedef struct flamingo_env_t flamingo_env_t;
typedef struct flamingo_arg_list_t flamingo_arg_list_t;

typedef int (*flamingo_external_fn_cb_t)(flamingo_t* flamingo, size_t name_size, char* name, void* data, flamingo_arg_list_t* args, flamingo_val_t** rv);
typedef int (*flamingo_external_fn_cb_t)(flamingo_t* flamingo, flamingo_val_t* callable, void* data, flamingo_arg_list_t* args, flamingo_val_t** rv);
typedef int (*flamingo_ptm_cb_t)(flamingo_t* flamingo, flamingo_val_t* self, flamingo_arg_list_t* args, flamingo_val_t** rv);

typedef enum {
Expand Down
5 changes: 4 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ static void usage(void) {
exit(EXIT_FAILURE);
}

static int external_fn_cb(flamingo_t* flamingo, size_t name_size, char* name, void* data, flamingo_arg_list_t* args, flamingo_val_t** rv) {
static int external_fn_cb(flamingo_t* flamingo, flamingo_val_t* callable, void* data, flamingo_arg_list_t* args, flamingo_val_t** rv) {
char* const name = callable->name;
size_t const name_size = callable->name_size;

if (flamingo_cstrcmp(name, "test_return_number", name_size) == 0) {
*rv = flamingo_val_make_int(420);
}
Expand Down

0 comments on commit 76b6ece

Please sign in to comment.