Embedding pawn into c++

43 views
Skip to first unread message

Habi Haris

unread,
Jul 3, 2020, 12:03:31 PM7/3/20
to Pawn Scripting Language
hi, i was trying to make a pawn compiler.

bool CScript::registerNatives(const AMX_NATIVE_INFO* list)
{
    err = amx_Register(&amx, list, -1);
    if (err != AMX_ERR_NONE)
    {
        Error(this->err);
        return false;
    }

    int num = -1;
    amx_NumNatives(&amx, &num);
    printf("Registered %i native functions.\n", num);
    return true;
}
void print(char* string)
{
    printf(string);
}
void print_int(int value)
{
    printf("%i\n", value);
}

void print_float(float value)
{
    printf("%f\n", value);
}

static cell AMX_NATIVE_CALL n_print_int(AMX* amx, const cell* params)
{
    print_int((int)params[1]);
    return 1;
}

static cell AMX_NATIVE_CALL n_print_float(AMX* amx, const cell* params)
{
    print_float(amx_ctof(params[1]));
    return 1;
}
static cell AMX_NATIVE_CALL n_print(AMX* amx, const cell* params)
{
    
    char output[128];
    
    print_int((int)params[1]);
    //printf("output is %s", output);
    return 1;
}
const AMX_NATIVE_INFO print_Natives[] =
{
    { "print_int", n_print_int },
    { "print_float", n_print_float },
    { "printx", n_print },
    {NULL,NULL}
    /* terminator */
};


and this is my pawn code
#include <string.inc>
#include <float.inc>
#include <console>
native print_int(value);
native print_float(value);
native printx( a);
new b=100;
main()
{
//console(45,10);
//printf( "Hello\n");
new a=10;
new Float:val = 10.111;

print_int(a);
print_float(val);
return 123;
}

public OnPlayerConnect(playerid)
{
    print_int(b);
    b=b+100;

}

i can print integer and floating points. But i have problem in printing string. If i use printf, amx is compiled using pawn IDE. i copy amx to game folder and runs the executable. the c++ code which i posted above is of executable ( more correctly, the executable can load plugins ( dll files) and i create a pawn4vcmp.dll ) so it all started working correctly, except with the string.
Thanks in advance.

Habi Haris

unread,
Jul 3, 2020, 2:10:25 PM7/3/20
to Pawn Scripting Language
hi i solved the problem myself.
It was console_Natives. Registered it. Also added #include "amscons.c"
Reply all
Reply to author
Forward
0 new messages