sourcemod/sourcepawn/vm/test_main.cpp
David Anderson d2cb27e20c added simple test procedure to VM and updated some context stuff for stack checking
--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40111
2006-10-10 02:06:50 +00:00

73 lines
1.6 KiB
C++

#include <stdio.h>
#include <sp_vm_api.h>
#include "sp_vm_engine.h"
#include "sp_vm_basecontext.h"
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
using namespace SourcePawn;
typedef void (*GIVEENGINE)(ISourcePawnEngine *);
typedef IVirtualMachine *(*GETEXPORT)(unsigned int);
int main()
{
SourcePawnEngine engine;
IVirtualMachine *vm;
ICompilation *co;
sp_plugin_t *plugin = NULL;
sp_context_t *ctx = NULL;
cell_t result;
int err;
/* Note: for now this is hardcoded for testing purposes!
* The ..\ should be one above msvc8.
*/
FILE *fp = fopen("..\\test.smx", "rb");
if (!fp)
{
return 0;
}
plugin = engine.LoadFromFilePointer(fp, &err);
if (err != SP_ERR_NONE)
{
printf("Error loading: %d", err);
return 0;
}
HMODULE dll = LoadLibrary("..\\jit\\x86\\msvc8\\Debug\\jit-x86.dll");
if (dll == NULL)
{
printf("Error loading DLL: %d\n", GetLastError());
return 0;
}
GIVEENGINE give_eng = (GIVEENGINE)GetProcAddress(dll, "GiveEnginePointer");
if (!give_eng)
{
printf("Error getting \"GiveEnginePointer!\"!\n");
return 0;
}
give_eng(&engine);
GETEXPORT getex = (GETEXPORT)GetProcAddress(dll, "GetExport");
if ((vm=getex(0)) == NULL)
{
printf("GetExport() returned no VM!\n");
return 0;
}
co = vm->StartCompilation(plugin);
ctx = vm->CompileToContext(co, &err);
IPluginContext *base = engine.CreateBaseContext(ctx);
base->PushCell(1);
base->PushCell(5);
err = base->Execute(0, &result);
printf("Result: %d Error: %d\n", result, err);
engine.FreeBaseContext(base);
fclose(fp);
FreeLibrary(dll);
}