From 61394e51a92e28963d82ded391ccf402a0157b5d Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 18 Mar 2018 17:03:57 +0100 Subject: Remove \callback Make the callback mechanism into one of general interception of any Storycode command. This way, the narrative rendering (the only thing using this functionality) doesn't have to do its horrible stylesheet thing. That's necessary so that the rendering function gets the actual SCBlock, not the definition of the macro. --- src/sc_interp.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src/sc_interp.c') diff --git a/src/sc_interp.c b/src/sc_interp.c index 0301aad..6914b13 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -216,15 +216,17 @@ void sc_interp_set_callbacks(SCInterpreter *scin, SCCallbackList *cbl) } -static void do_callback(SCInterpreter *scin, SCBlock *bl, const char *name) +static int check_callback(SCInterpreter *scin, SCBlock *bl) { int i; + const char *name = sc_block_name(bl); SCCallbackList *cbl = scin->cbl; - if ( cbl == NULL ) { - fprintf(stderr, "No callback list.\n"); - return; - } + /* No callback list -> easy */ + if ( cbl == NULL ) return 0; + + /* No name -> definitely not a callback */ + if ( name == NULL ) return 0; for ( i=0; in_callbacks; i++ ) { @@ -240,15 +242,16 @@ static void do_callback(SCInterpreter *scin, SCBlock *bl, const char *name) if ( strcmp(cbl->names[i], name) != 0 ) continue; r = cbl->box_funcs[i](scin, bl, &w, &h, &bvp, cbl->vps[i]); - if ( !r ) return; - add_callback_para(sc_interp_get_frame(scin), bl, rbl, w, h, - cbl->draw_funcs[i], cbl->click_funcs[i], - bvp, cbl->vps[i]); + if ( r ) { + add_callback_para(sc_interp_get_frame(scin), bl, w, h, + cbl->draw_funcs[i], cbl->click_funcs[i], + bvp, cbl->vps[i]); + } + return 1; - return; } - fprintf(stderr, "Unknown callback '%s'\n", name); + return 0; } @@ -1143,6 +1146,9 @@ int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl) exec_macro(bl, scin, child); sc_interp_restore(scin); + } else if ( check_callback(scin, bl) ) { + /* Handled in check_callback, don't do anything else */ + } else if ((sc_interp_get_frame(scin) != NULL) && check_outputs(bl, scin) ) { /* Block handled as output thing */ @@ -1209,9 +1215,6 @@ int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl) set_paraspace(scin, options); maybe_recurse_after(scin, child); - } else if ( strcmp(name, "callback") == 0 ) { - do_callback(scin, bl, options); - } else { //fprintf(stderr, "Don't know what to do with this:\n"); -- cgit v1.2.3