fixed a serious bug with byref values and callfunc_push*() where the heap was used incorrectly, causing passed data to be easily corrupted.
added callfunc_push_array() (am42810)
This commit is contained in:
@ -647,6 +647,7 @@ native callfunc_push_str(const VALUE[]);
|
||||
native callfunc_push_float(Float: value);
|
||||
native callfunc_push_intrf(&value);
|
||||
native callfunc_push_floatrf(& Float: value);
|
||||
native callfunc_push_array(const VALUE[], array_size);
|
||||
|
||||
/* Make the actual call.
|
||||
* Return value of the function called. */
|
||||
|
56
plugins/testsuite/callfunc_test.sma
Normal file
56
plugins/testsuite/callfunc_test.sma
Normal file
@ -0,0 +1,56 @@
|
||||
#include <amxmodx>
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("callfunc test", "1.0", "BAILOPAN")
|
||||
|
||||
register_srvcmd("test_callfunc", "Command_Callfunc")
|
||||
}
|
||||
|
||||
public OnCallfuncReceived(num, str[], &val, array[], array2[], size)
|
||||
{
|
||||
server_print("num = %d (expected: %d)", num, 5)
|
||||
server_print("str[] = ^"%s^" (expected: %s)", str, "Gaben")
|
||||
|
||||
server_print("val = %d (expected %d, setting to %d)", val, 62, 15)
|
||||
val = 15
|
||||
server_print("printing %d elements of array[] (expected: %d)", size, 6)
|
||||
for (new i=0; i<size; i++)
|
||||
{
|
||||
server_print("array[%d] = %d (expected: %d)", i, array[i], i)
|
||||
}
|
||||
for (new i=0; i<size; i++)
|
||||
{
|
||||
server_print("array2[%d] = %d (expected: %d)", i, array[i], i)
|
||||
}
|
||||
array[0] = 5
|
||||
array2[1] = 6
|
||||
}
|
||||
|
||||
public Command_Callfunc()
|
||||
{
|
||||
new a = 62
|
||||
new hello[] = {0,1,2,3,4,5}
|
||||
new pm = 6
|
||||
new err
|
||||
|
||||
if ((err=callfunc_begin("OnCallfuncReceived")) < 1)
|
||||
{
|
||||
server_print("Failed to call callfunc_begin()! Error: %d", err)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
callfunc_push_int(5)
|
||||
callfunc_push_str("Gaben")
|
||||
callfunc_push_intrf(a)
|
||||
callfunc_push_array(hello, pm)
|
||||
callfunc_push_array(hello, pm)
|
||||
callfunc_push_int(pm)
|
||||
callfunc_end()
|
||||
|
||||
server_print("a = %d (expected: %d)", a, 15)
|
||||
server_print("hello[0] = %d (expected: %d)", hello[0], 5)
|
||||
server_print("hello[1] = %d (expected: %d)", hello[1], 6)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
Reference in New Issue
Block a user