AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   register_native natives and ... parameters (https://forums.alliedmods.net/showthread.php?t=56445)

XxAvalanchexX 06-14-2007 00:55

register_native natives and ... parameters
 
Here is a function prototype in Plugin A:

Code:
public func(a,b,c[],{Float,Sql,Result,_}:...)

I would like to call this with a register_native native (that is registered in Plugin A) from Plugin B. I know that I can collect all of the arguments using native style 1 like this:

Code:
public func_native_handler(a,b,c[],{Float,Sql,Result,_}:...) {     param_convert(3);           new i, argnum = numargs();     for(i=4;i<=argnum;i++) param_convert(i); }

However, from here I need to make a direct call to "func" with all of these extra parameters, which could be of any variable type. I can't use vformat or anything and then send the condensed result into "func". The only thing that I could come up with was callfunc, except that I can't get the parameter types required for each specific native.

Any suggestions?

XxAvalanchexX 06-14-2007 02:37

Re: register_native natives and ... parameters
 
I decided that only integers and strings would be fine, so I tried this. It sort of works, except that the "getarg(i-1,1)" check comes back true for integers. I think that it's dipping into other memory, because when I use two separate integers they both result in the same string being formed. Are there any other ways to differentiate between a string and an int that you know of?

Code:
public func_native_handler(a,b,c[],{Float,Sql,Result,_}:...) {     param_convert(3);         static funcid;     if(!funcid) funcid = get_func_id("func");         callfunc_begin_i(funcid);     callfunc_push_int(a);     callfunc_push_int(b);     callfunc_push_str(c);         static buildString[128];     new i, j, argnum = numargs();     for(i=4;i<=argnum;i++)     {         param_convert(i);         if(getarg(i-1,1))         {             j = 0;             while(getarg(i-1,j))             {                 buildString[j] = getarg(i-1,j);                 j++;             }             buildString[j] = 0; // finish string             callfunc_push_str(buildString);         }         else callfunc_push_int(getarg(i-1));     }         callfunc_end(); }

Greenberet 06-14-2007 05:31

Re: register_native natives and ... parameters
 
Code:
//bla.inc /** * c ^ cell * s ^ string * a ^ array * * plugin < 0 calls executing plugin * * ex. ForceCall( 0, "punishClient", "ccs", Client, Victim, "H4xx0r" ); * **/ // Deprecated native ForceCall ( plugin, const name[], const format[], any:... ); //bla.sma register_native( "ForceCall", "__ForceCall" ); //... public __ForceCall ( CPlugin, CParams ) {     static plugin, name[ 31 ], format[ 14 ], func_id, source[ 65 ], p_format, param;         plugin = get_param( 1 );     get_string( 2, name, 30 );     if ( plugin < 0 )         plugin = CPlugin;             func_id = get_func_id( name, plugin );     if ( func_id < 0 )         return -1;             get_string( 3, format, 13 );             if ( strlen( format ) != CParams - 3 )     {         log_error( AMX_ERR_NATIVE, "<< CORE >> format doesn't match parameters" );                 return 0;     }     if ( callfunc_begin_i( func_id, plugin ) != 1 )     {         log_error( AMX_ERR_NATIVE, "<< CORE >> God seems to hate ya" );                 return 0;     }         p_format = 0;     for ( param = 4; param <= CParams; param++ )     {         switch ( format[ p_format ] )         {             case 'c':             {                 callfunc_push_int( get_param_byref( param ) );             }                         case 's':             {                 get_string( param, source, 63 );                 callfunc_push_str( source );             }                         case 'a':             {                 callfunc_push_int( get_param( param ) );             }             default:             {                 log_error( AMX_ERR_NATIVE, "<< CORE >> What's '%c' ?", format[ p_format ] );             }         }                 ++p_format;     }     return callfunc_end(); }

XxAvalanchexX 06-14-2007 13:49

Re: register_native natives and ... parameters
 
Wow, that's really nice. I should be able to find a way to use it in my situation. Thanks.

Greenberet 06-14-2007 15:11

Re: register_native natives and ... parameters
 
to use it in your situation shoudnt be hard^^

ForceCall( Plugin, "func", "cca", 3,1, your_array );


All times are GMT -4. The time now is 10:44.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.