[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
#2

What it used for ?
Reply
#3

Quote:
Originally Posted by xkirill
Посмотреть сообщение
What it used for ?
Well, I'm using it in my rCmd.inc for example. You could also call functions in-game with this (just an idea).
Reply
#4

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
Well, I'm using it in my rCmd.inc for example. You could also call functions in-game with this (just an idea).
When to use it?
Reply
#5

You should give examples.
Reply
#6

Quote:
Originally Posted by Arca
Посмотреть сообщение
When to use it?
Sorry, what do you mean by that? I think everything is clear.

Quote:
Originally Posted by MP2
Посмотреть сообщение
You should give examples.
No offense, but can't you see the big-ass "Examples" title in the main post?
Reply
#7

Nice one!
I was searching something like this some time ago
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)