initial import of dynamic native code for both the JIT and plugins

note: dependency resolution is not done yet!

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40607
This commit is contained in:
David Anderson
2007-03-12 07:08:05 +00:00
parent 7ab8e2027b
commit 7c06d89b00
14 changed files with 963 additions and 5 deletions
+85
View File
@@ -0,0 +1,85 @@
#include <sourcemod>
public Plugin:myinfo =
{
name = "FakeNative Testing Lab #1",
author = "AlliedModders LLC",
description = "Test suite #1 for dynamic natives",
version = "1.0.0.0",
url = "http://www.sourcemod.net/"
};
public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max)
{
CreateNative("TestNative1", __TestNative1);
CreateNative("TestNative2", __TestNative2);
CreateNative("TestNative3", __TestNative3);
CreateNative("TestNative4", __TestNative4);
CreateNative("TestNative5", __TestNative5);
return true;
}
public __TestNative1(Handle:plugin, numParams)
{
PrintToServer("TestNative1: Plugin: %x params: %d", plugin, numParams);
if (numParams == 4)
{
ThrowNativeError(SP_ERROR_NATIVE, "Four parameters ARE NOT ALLOWED lol");
}
return 5;
}
public __TestNative2(Handle:plugin, numParams)
{
new String:buffer[512];
new bytes;
GetNativeString(1, buffer, sizeof(buffer), bytes);
for (new i=0; i<bytes; i++)
{
buffer[i] = buffer[i] + 1;
}
SetNativeString(1, buffer, bytes+1);
}
public __TestNative3(Handle:plugin, numParams)
{
new val1 = GetNativeCell(1);
new val2 = GetNativeCellRef(2);
SetNativeCellRef(2, val1+val2);
}
public __TestNative4(Handle:plugin, numParams)
{
new size = GetNativeCell(3);
new local[size];
GetNativeArray(1, local, size);
SetNativeArray(2, local, size);
}
public __TestNative5(Handle:plugin, numParams)
{
new local = GetNativeCell(1);
if (local)
{
FormatNativeString(2, 4, 5, GetNativeCell(3));
} else {
new len = GetNativeCell(3);
new fmt_len;
new String:buffer[len];
GetNativeStringLength(4, fmt_len);
new String:format[fmt_len];
GetNativeString(2, buffer, len);
GetNativeString(4, format, fmt_len);
FormatNativeString(0, 0, 5, len, _, buffer, format);
}
}
+87
View File
@@ -0,0 +1,87 @@
#include <sourcemod>
native TestNative1(gaben, ...);
native TestNative2(String:buffer[]);
native TestNative3(value1, &value2);
native TestNative4(const input[], output[], size);
native TestNative5(bool:local, String:buffer[], maxlength, const String:fmt[], {Handle,Float,String,_}:...);
public Plugin:myinfo =
{
name = "FakeNative Testing Lab #2",
author = "AlliedModders LLC",
description = "Test suite #2 for dynamic natives",
version = "1.0.0.0",
url = "http://www.sourcemod.net/"
};
public OnPluginStart()
{
RegServerCmd("test_native1", Test_Native1);
RegServerCmd("test_native2", Test_Native2);
RegServerCmd("test_native3", Test_Native3);
RegServerCmd("test_native4", Test_Native4);
RegServerCmd("test_native5", Test_Native5);
}
public Action:Test_Native1(args)
{
PrintToServer("Returned: %d", TestNative1(1));
PrintToServer("Returned: %d", TestNative1(1,2));
PrintToServer("Returned: %d", TestNative1(1,2,3,4));
return Plugin_Handled;
}
public Action:Test_Native2(args)
{
new String:buffer[] = "IBM";
PrintToServer("Before: %s", buffer);
TestNative2(buffer);
PrintToServer("AfteR: %s", buffer);
return Plugin_Handled;
}
public Action:Test_Native3(args)
{
new value1 = 5, value2 = 6
PrintToServer("Before: %d, %d", value1, value2);
TestNative3(value1, value2);
PrintToServer("After: %d, %d", value1, value2);
return Plugin_Handled;
}
public Action:Test_Native4(args)
{
new input[5] = {0, 1, 2, 3, 4};
new output[5];
TestNative4(input, output, 5);
PrintToServer("[0=%d] [1=%d] [2=%d] [3=%d] [4=%d]", input[0], input[1], input[2], input[3], input[4]);
PrintToServer("[0=%d] [1=%d] [2=%d] [3=%d] [4=%d]", output[0], output[1], output[2], output[3], output[4]);
return Plugin_Handled;
}
public Action:Test_Native5(args)
{
new String:buffer1[512];
new String:buffer2[512];
TestNative5(true, buffer1, sizeof(buffer1), "%d gabens in the %s", 50, "gabpark");
TestNative5(true, buffer2, sizeof(buffer2), "%d gabens in the %s", 50, "gabpark");
PrintToServer("Test 1: %s", buffer1);
PrintToServer("Test 2: %s", buffer2);
return Plugin_Handled;
}