I've been trying and thinking on how to make a module that messages "hello world" ingame to all players, but I obviously fail at it, here is my C file ( as the headers and other requested files are included )
NOTE: 1. I've been seeking help on IRC but it seems I am too annoying for this comunity with my obvious annoying PMs.
2. I know this is not a place to request C++ Help.
#include "SQFuncs.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdio.h>
#include <sqstdaux.h>
#include <sqstdio.h>
#ifdef SQUNICODE
#define scvprintf vwprintf
#else
#define scvprintf vprintf
#endif
extern SQAPI sq;
//_SQUIRRELDEF( MessagePeople )
//{
/*SQUIRREL_API SQRESULT sq_compile(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror);*/
// char phat [] = "hello world";
//sq->pushstring( v, _SC(" Message(phat) "), -1 );
//sq->call( v, _SC("Message(phat) "), true, true );
//sq->call( v, _SC("Message(phat); "), true, true );
// return SQ_OK;
//}
_SQUIRRELDEF( HelloSquirrel )
{
sq->pushstring( v, _SC( "Hello Squirrel Module!" ), -1 );
return 1; /* return 0 indicates the Squirrel function does not return a value, 1 returns a value */
}
_SQUIRRELDEF( Sum )
{
SQInteger iArgCount = sq->gettop( v ); /* Get the argument count */
if ( iArgCount == 3 ) /* Argument count = 2 arguments + root table = 3 */
{
SQInteger i1 = 0, i2 = 0;
sq->getinteger( v, 2, &i1 ); /* Get argument 1 in slot 2 to 'i1' */
sq->getinteger( v, 3, &i2 ); /* Get argument 2 in slot 3 to 'i2' */
sq->pushinteger( v, i1 + i2 ); /* Return the sum of these two numbers */
return 1;
}
sq->pushbool( v, SQFalse );
return 1;
}
void printfunc(HSQUIRRELVM v, const SQChar *s, ...)
{
va_list arglist;
va_start(arglist, s);
scvprintf(s, arglist);
va_end(arglist);
}
void call_Message(HSQUIRRELVM v, const SQChar *s)
{
int top = sq->gettop(v); //saves the stack size before the call
sq->pushroottable(v); //pushes the global table
sq->pushstring(v,_SC("Message"),-1);
if(SQ_SUCCEEDED(sq->get(v,-2))) { //gets the field 'foo' from the global table
sq->pushroottable(v); //push the 'this' (in this case is the global table)
sq->pushstring(v,s,-1);
sq->call(v,2,0,0); //calls the function
}
sq->settop(v,top); //restores the original stack size
}
int main(int argc, char* argv[])
{
HSQUIRRELVM v;
v = sq->open(1024); // creates a VM with initial stack size 1024
// sq->seterrorhandlers(v);
sq->setprintfunc(v, printfunc, NULL); //sets the print function
sq->pushroottable(v); //push the root table(were the globals of the script will be stored)
// if(SQ_SUCCEEDED(sq->dofile(v, _SC("SRPGv0.1.nut"), 0, 1))) // also prints syntax errors if any
// {
call_Message(v,_SC("teststring"));
// }
sq->pop(v,1); //pops the root table
sq->close(v);
return 0;
}
SQInteger RegisterSquirrelFunc( HSQUIRRELVM v, SQFUNCTION f, const SQChar* fname, unsigned char ucParams, const SQChar* szParams )
{
char szNewParams[ 32 ];
sq->pushroottable( v );
sq->pushstring( v, fname, -1 );
sq->newclosure( v, f, 0 ); /* create a new function */
if ( ucParams > 0 )
{
ucParams++; /* This is to compensate for the root table */
sprintf( szNewParams, "t%s", szParams );
sq->setparamscheck( v, ucParams, szNewParams ); /* Add a param type check */
}
sq->setnativeclosurename( v, -1, fname );
sq->newslot( v, -3, SQFalse );
sq->pop( v, 1 ); /* pops the root table */
return 0;
}
void RegisterFuncs( HSQUIRRELVM v )
{
/* Add your Squirrel functions here */
RegisterSquirrelFunc( v, HelloSquirrel, "Hello", 0, 0 );
RegisterSquirrelFunc( v, Sum, "Sum", 2, "ii" );
//RegisterSquirrelFunc( v, MessagePeople, "MessagePeople", NULL, NULL );
}