[Include] DynamicParams.inc
#1

DynamicParams.inc

I promised to start a topic about this include in my rCmd.inc topic a while ago, but I forgot about it - so here it is. It's basically an include to call functions (not natives) dynamically; you can push all parameters apart and then call the function itself wherever you want.

Functions

These are the types you can push:
pawn Код:
enum e_Types {
    Mixed,
    String,
    ByRef
};
Here are the main functions:
pawn Код:
stock Push_Param(const e_Types: iType, { Float, _ }: ...);
stock Set_Param(const e_Types: iType, iIdx, { Float, _ }: ...);
stock Pop_Param();
stock CallFunction(const szName[], const bool: bPop = true);
Examples

pawn Код:
public OnFilterScriptInit() {
    new
        Float: fFloat = 360.0
    ;
    Push_Param(Mixed, fFloat);
    Push_Param(Mixed, 50000);
   
    new
        iIdx = Push_Param(String, "Bla Bla!")
    ;
    Set_Param(String, iIdx, "Oh sorry, wrong string!");
   
    new
        iInteger2,
        Float: fFloat2,
        szBuf[32]
    ;
    Push_Param(ByRef, iInteger2);
    Push_Param(ByRef, fFloat2);
    Push_Param(String, szBuf);
   
    CallFunction("foo", .bPop = true);
   
    printf("%d %f %s", iInteger2, fFloat2, szBuf); // 12345 270.000000 Hello World!
   
    return 1;
}
pawn Код:
forward foo(Float: fFloat, iInteger, szStr[], &iInteger2, &Float: fFloat2, szBuf[]); public foo(Float: fFloat, iInteger, szStr[], &iInteger2, &Float: fFloat2, szBuf[]) {
    printf("%f %d %s", fFloat, iInteger, szStr); // 360.000000 50000 Oh sorry, wrong string!
   
    iInteger2 = 12345;
    fFloat2 = 270.0;
   
    strcat(szBuf, "Hello World!", 32);
}
Prints:
pawn Код:
360.000000 50000 Oh sorry, wrong string!
12345 270.000000 Hello World!
Download

DynamicParams.inc
Reply


Messages In This Thread
DynamicParams.inc - by RyDeR` - 30.07.2012, 09:47
Re: DynamicParams.inc - by Kaperstone - 30.07.2012, 09:48
Re: DynamicParams.inc - by RyDeR` - 30.07.2012, 18:17
Re: DynamicParams.inc - by Arca - 30.07.2012, 18:20
Re: DynamicParams.inc - by MP2 - 30.07.2012, 20:15
Re: DynamicParams.inc - by RyDeR` - 30.07.2012, 21:00
Re: DynamicParams.inc - by FireCat - 30.07.2012, 21:56

Forum Jump:


Users browsing this thread: 1 Guest(s)