tags:

views:

36

answers:

1

I'm trying to use AS3_Shim in my alchemy code but it doesn't seem to be working. It always returns a NULL function pointer. There don't seem to be any examples of AS3_Shim's use, so I'm not sure what I'm doing wrong. Here is some example code:

static AS3_Val thunk_logtest(void *self, AS3_Val args) {

    // warning: this leaks
    AS3_Val ns= AS3_String("mx.logging");
    AS3_Val clazz= AS3_NSGetS(ns, "Log");
    AS3_Val logger= AS3_CallTS("getLogger", clazz, "StrType", "alchemy");

    // works
    AS3_Val logret= AS3_CallTS("debug", logger, "StrType", "this is a test");

    // doesn't work: AS3_Shim returns NULL!
    typedef void (*log_func_t)(const char[], ...);   
    log_func_t log_func= (log_func_t)AS3_Shim(AS3_String("debug"), logger, "VoidType", "StrType", true);
    printf("log_func= %d \n", log_func); fflush(stdout);

    // because log_func is NULL, this throws TypeError: Error #1006: value is not a function
    log_func("this is a test");

    return AS3_Undefined();
}
A: 

AS3_Shim expects a function for its first parameter, not a function name. Replace AS3_String("debug") with AS3_GetS(logger, "debug")

log_func_t log_func = (log_func_t)AS3_Shim(
    AS3_GetS(logger, "debug"), logger, "VoidType", "StrType", true );
Gunslinger47
OHHhhhh... It was highly unclear from the docs what they meant. I didn't realize you could use AS3_Get to get a function (I thought it was just for properties). Thanks!
paleozogt
@paleo: You can also use it to access Array elements by sending the desired index as a String.
Gunslinger47