plugins/testsuite/fakenative1.sp
author David Anderson <dvander@alliedmods.net>
Sat Jun 16 08:35:26 2007 +0000 (2007-06-16)
changeset 949 4cc7fd7adb8a
parent 601 fe5b368fcedc
permissions -rw-r--r--
added handle reading to GameConfigManager
     1 #include <sourcemod>
     2 
     3 public Plugin:myinfo = 
     4 {
     5 	name = "FakeNative Testing Lab #1",
     6 	author = "AlliedModders LLC",
     7 	description = "Test suite #1 for dynamic natives",
     8 	version = "1.0.0.0",
     9 	url = "http://www.sourcemod.net/"
    10 };
    11 
    12 public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max)
    13 {
    14 	CreateNative("TestNative1", __TestNative1);
    15 	CreateNative("TestNative2", __TestNative2);
    16 	CreateNative("TestNative3", __TestNative3);
    17 	CreateNative("TestNative4", __TestNative4);
    18 	CreateNative("TestNative5", __TestNative5);
    19 	return true;
    20 }
    21 
    22 public __TestNative1(Handle:plugin, numParams)
    23 {
    24 	PrintToServer("TestNative1: Plugin: %x params: %d", plugin, numParams);
    25 	if (numParams == 4)
    26 	{
    27 		ThrowNativeError(SP_ERROR_NATIVE, "Four parameters ARE NOT ALLOWED lol");
    28 	}
    29 	return 5;
    30 }
    31 
    32 public __TestNative2(Handle:plugin, numParams)
    33 {
    34 	new String:buffer[512];
    35 	new bytes;
    36 	
    37 	GetNativeString(1, buffer, sizeof(buffer), bytes);
    38 	
    39 	for (new i=0; i<bytes; i++)
    40 	{
    41 		buffer[i] = buffer[i] + 1;
    42 	}
    43 	
    44 	SetNativeString(1, buffer, bytes+1);
    45 }
    46 
    47 public __TestNative3(Handle:plugin, numParams)
    48 {
    49 	new val1 = GetNativeCell(1);
    50 	new val2 = GetNativeCellRef(2);
    51 	
    52 	SetNativeCellRef(2, val1+val2);
    53 }
    54 
    55 public __TestNative4(Handle:plugin, numParams)
    56 {
    57 	new size = GetNativeCell(3);
    58 	new local[size];
    59 	
    60 	GetNativeArray(1, local, size);
    61 	SetNativeArray(2, local, size);
    62 }
    63 
    64 public __TestNative5(Handle:plugin, numParams)
    65 {
    66 	new local = GetNativeCell(1);
    67 	
    68 	if (local)
    69 	{
    70 		FormatNativeString(2, 4, 5, GetNativeCell(3));
    71 	} else {
    72 		new len = GetNativeCell(3);
    73 		new fmt_len;
    74 		new String:buffer[len];
    75 			
    76 		GetNativeStringLength(4, fmt_len);
    77 		
    78 		new String:format[fmt_len];
    79 		
    80 		GetNativeString(2, buffer, len);
    81 		GetNativeString(4, format, fmt_len);
    82 		
    83 		FormatNativeString(0, 0, 5, len, _, buffer, format);
    84 	}
    85 }