paleozogt
paleozogt

Reputation: 6563

Alchemy's AS3_Shim broken?

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();
}

Upvotes: 2

Views: 247

Answers (1)

Gunslinger47
Gunslinger47

Reputation: 7061

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 );

Upvotes: 1

Related Questions