30.07.2012, 09:47
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:
Here are the main functions:
Examples
Prints:
Download
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
};
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);
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);
}
pawn Код:
360.000000 50000 Oh sorry, wrong string!
12345 270.000000 Hello World!
DynamicParams.inc