I'm trying to write a very basic app to test how pawn with c++ works, tough I'm having some issues.
Since amxx mod x is based of pawn I taught that someone could help me.
Heres my c++ app code:
Code:
#include <stdio.h>
#include <string.h>
#include "amx/amx.h"
#include "amx/amxaux.h"
void print_int(int stuff)
{
printf("%i\n",stuff);
}
static cell AMX_NATIVE_CALL n_print_int(AMX *amx, const cell *params)
{
print_int( (int)params[1] );
}
extern "C"
int amx_PrintInit(AMX *amx)
{
static AMX_NATIVE_INFO print_Natives[] =
{
{ "print_int", n_print_int },
{ 0, 0 }
/* terminator */
};
return amx_Register(amx, print_Natives, -1);
}
int amx_PrintCleanup(AMX *amx)
{
return AMX_ERR_NONE;
}
void ErrorExit(AMX *amx, int errorcode)
{
printf("Run time error %d: \"%s\"\n",
errorcode, aux_StrError(errorcode));
exit(1);
}
void PrintUsage(char *program)
{
printf("Usage: %s <filename>\n", program);
exit(1);
}
int main(int argc,char *argv[])
{
size_t memsize;
void *program;
AMX amx;
cell ret = 0;
int err;
cell index;
memsize = aux_ProgramSize("1st.amx");
program = malloc(memsize);
if (program == NULL)
ErrorExit(&amx, err);
err = aux_LoadProgram(&amx, "1st.amx", program);
if (err)
ErrorExit(&amx, err);
err=amx_PrintInit(&amx);
if (err == AMX_ERR_NONE)
printf("SUCCESS?\n");
else
ErrorExit(&amx, err);
err = amx_FindNative(&amx, "print_int", &index);
if (err == AMX_ERR_NONE)
printf("SUCCESS?\n");
else
ErrorExit(&amx, err);
err = amx_Exec(&amx, &ret, AMX_EXEC_MAIN);
if (err)
ErrorExit(&amx, err);
if (ret != 0)
printf("%s returns %ld\n", "1st.amx", (long)ret);
amx_PrintCleanup(&amx);
amx_Cleanup(&amx);
free(program);
printf("BYE!!!!\n");
//VirtualFree(program, 0, MEM_RELEASE);
return 0;
}
heres p code(1st.p):
Code:
#include "test.inc"
public foo()
{
return 1
}
main()
{
//print_int(1)
return 100
}
heres test.inc:
Code:
native print_int(value)
I compile the p code with the pawn compiler which I got with the library and everything compiles correctly and the 1st.amx is produced.
I put my 1st.amx into my apps folder.
Launch the app.
It fails at finding native func print_int.
what am I doing wrong?