moparisthebest
2010-09-22 17:23:03
I'm trying to figure out the proper way to write and compile a Simba plugin so it will work on all OSs and architectures, the first step of course is to simplify it as much as possible and get it to work on win32 Simba. I took yakman's markov plugin and converted it to this:
I compile it with this makefile:
Here is my simba script:
Which produces:
Now the big question: What did I do wrong?
#include <windows.h>
#include <assert.h>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
//plugin stuff below
#define DLL_EXPORT _declspec(dllexport)
#define SIMBA_EXPORT DLL_EXPORT __stdcall
//#define SIMBA_EXPORT __stdcall
//#define DLL_EXPORT __stdcall
#ifdef __cplusplus
extern "C" {
#endif
int SIMBA_EXPORT
fast_add_ten(int num) {
return num + 10;
}
char* function_defs[] = {
(char*)"function FastAddTen(num: Integer): Integer;"
};
void* function_ptrs[] = {
(void*)&fast_add_ten
};
int SIMBA_EXPORT
GetFunctionCount(void) {
assert(sizeof(function_defs) == sizeof(function_ptrs));
//printf("GetFunctionCount()\n");
return sizeof(function_defs) / sizeof(char*);
}
int SIMBA_EXPORT
GetFunctionInfo(int x, void** proc_addr, char** proc_def) {
//printf("GetFunctionInfo(%d, 0x%08x, 0x%08x)\n", x, proc_addr, proc_def);
if(x < 0 || x > sizeof(function_defs) / sizeof(char*))
return -1;
*proc_addr = function_ptrs[x];
strcpy(*proc_def, function_defs[x]);
return x;
}
DLL_EXPORT BOOL WINAPI
DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
//AllocConsole();
return TRUE;
}
#ifdef __cplusplus
}
#endif
I compile it with this makefile:
CC := i586-mingw32msvc-g++
PLATFORM_FLAGS := -mwindows -shared -s
CFLAGS := -O2 -fomit-frame-pointer
OUTPUT := ./libtest.dll
default: $(OUTPUT)
$(OUTPUT):
$(CC) $(CFLAGS) $(PLATFORM_FLAGS) -o $(OUTPUT) test.cpp
clean:
rm -f *.o *.so *.dllHere is my simba script:
program new;
{.loadlib libtest}
var
num: Integer;
begin
ClearDebug;
num := 32;
Writeln('num = ' + IntToStr(num));
Writeln('num := num + 10;');
num := num + 10;
Writeln('num = ' + IntToStr(num));
Writeln('num := FastAddTen(num);');
num := FastAddTen(num);
Writeln('num = ' + IntToStr(num));
end.Which produces:
Loading plugin libtest at /home/mopar/simba/test/Plugins\
formWriteln: [Error] (14:8): Unknown identifier 'FastAddTen' at line 13
formWriteln: Compiling failed.Now the big question: What did I do wrong?