SquirrelScriptContext* SquirrelScriptContext::CreateContext(int stackSize)
{
	SquirrelScriptContext* context = new SquirrelScriptContext();

	HSQUIRRELVM vm = sq_open(stackSize);
	vm->user_data = context;

	sq_setprintfunc(vm, SquirrelPrintCallback);
	sqstd_seterrorhandlers(vm);

	// Push root table so stdlibs can register themselves to it
	sq_pushroottable(vm);

	// Register stdlibs
	sqstd_register_iolib(vm);
	sqstd_register_mathlib(vm);
	sqstd_register_stringlib(vm);
	sqstd_register_systemlib(vm);

	context->m_vm = vm;

	return context;
}
Example #2
0
/*
** Creates a new SQuirrel vm.
*/
static SQRESULT sq_slave_vm_constructor (HSQUIRRELVM v)
{
    SQ_FUNC_VARS(v);
    SQ_OPT_INTEGER(v, 2, stack_size, 1024);
    HSQUIRRELVM self = sq_open(stack_size);

    /* Initialize environment */
    sq_setprintfunc(self,sq_getprintfunc(v),sq_geterrorfunc(v));

    /* load base libraries */
    sq_pushroottable(self);

    sqstd_register_bloblib(self);
    sqstd_register_iolib(self);
    sqstd_register_systemlib(self);
    sqstd_register_mathlib(self);
    sqstd_register_stringlib(self);
    sq_poptop(self); //remove root table

    sq_setinstanceup(v, 1, self);
    sq_setreleasehook(v, 1, sq_slave_vm_release_hook);

    return 1;
}
Example #3
0
void MTR_ScriptsInit(void)
{
    #ifdef MTR_MOD_PLUGIN
    int i;
    int j;
    #endif

    MTR_LogWrite("Initializing script subsystem", 0, MTR_LMT_INFO);

    MTR_LogWrite_s("Reporting Squirrel compile-time version:", 1, MTR_LMT_INFO,
     SQUIRREL_VERSION);
    MTR_LogWrite_i("Reporting Squirrel linked version:", 1, MTR_LMT_INFO,
     sq_getversion());

    mtrVm = sq_open(1024);
    sq_setprintfunc(mtrVm, MTR_ScriptPrintFunc, MTR_ScriptErrorFunc); //sets the print function
    sq_pushroottable(mtrVm);
    sqstd_register_bloblib(mtrVm);
    sqstd_register_iolib(mtrVm);
    sqstd_register_systemlib(mtrVm);
    sqstd_register_mathlib(mtrVm);
    sqstd_register_stringlib(mtrVm);
    sqstd_seterrorhandlers(mtrVm); //registers the default error handlers
    MTR_LogWrite("Squirrel VM created", 1, MTR_LMT_INFO);
    /* Registering functions and constants from all binding plugins */
    MTR_LogWrite("Registering functions and constants of engine", 1,
     MTR_LMT_INFO);

    MTR_ScriptsRegisterAll();

    MTR_LogWrite("Script functions and constants of engine registered",
     1, MTR_LMT_INFO);
    /* Registering functions and constants from all binding plugins */
    MTR_LogWrite("Registering functions and constants of bindings", 1,
     MTR_LMT_INFO);
    #ifdef MTR_MOD_PLUGIN
    for (i = 0; i < mtrPluginsCount; i++)
    {
        for (j = 0; j < mtrPluginData[i].report->prereqsCount; j++)
        {
            if (strcmp(mtrPluginData[i].report->prereqs[j], "Script_Squirrel") == 0)
            {
                MTR_LogWrite_s("Binding found:", 2, MTR_LMT_INFO,
                 mtrPluginData[i].report->moduleID);
                MTR_PluginInit = (mtrPluginInitFunc)MTR_FindFunction(
                 mtrPluginData[i].report->moduleID, "MTR_PluginInit");
                if (MTR_PluginInit != NULL)
                    MTR_PluginInit();
                else
                    MTR_Notify("Library not contain MTR_PluginInit function", 3,
                     MTR_LMT_ERROR);
            }
        }
    }
    #else
        MTR_BifInitAll();
    #endif

    MTR_LogWrite("Script functions and constants of bindings registered",
     1, MTR_LMT_INFO);
    MTR_LogWrite("Script subsystem initialized", 0, MTR_LMT_INFO);
}
Example #4
0
CResourceScript::CResourceScript ( CString strFile, int ScriptType, CResource *pResource )
{
	// Warp some varibles.
	m_pResource = pResource;
	m_iScriptType = ScriptType;

	// Format script localization.
	m_strFile.Format("%s\\%s\\%s", m_pResource->GetDirectory().Get(), m_pResource->GetName().Get(), strFile.Get());

	// Check if file exists.
	if(!Exists(m_strFile.Get()))
	{
		CLog::Printf( "[Resources] Script %s not found!", m_strFile.Get() );
		return;
	}

	// Check script type - default server.
	if ( ScriptType == SCRIPT_CLIENT )
	{
		/*
			TODO:
				- Warp to code WebServ,
				- Create class for client resources,
				- ..
		*/
	} else {
		// Create root stack for script.
		m_pVM = sq_open(1024);

		//Register error and print functions.
		sqstd_seterrorhandlers(m_pVM);
		sq_setprintfunc(m_pVM, PrintFunction, ErrorFunction);
		sq_setcompilererrorhandler(m_pVM, CompilerErrorFunction);

		// Push root vm table.
		sq_pushroottable(m_pVM);

		// Register basic systems.
		sqstd_register_systemlib(m_pVM);
		sqstd_register_iolib(m_pVM);
		sqstd_register_bloblib(m_pVM);
		sqstd_register_mathlib(m_pVM);
		sqstd_register_stringlib(m_pVM);

		// Register Squirrel Classes
		m_pResource->RegisterClass(this);
		
		// Register all functions.

		// Event functions.
		CEventNatives::Register(this);

		// Funkcje gracza.
		CPlayerNatives::Register(this);

		if ( SQ_FAILED ( sqstd_dofile(m_pVM, m_strFile.Get(), SQFalse, SQTrue) ) )
		{
			// cannot compile script file.
			return;
		}

		// Define basic varibles.
		CSquirrelArguments pArgs;
		pArgs.push(MAX_PLAYERS);
		RegisterVarible ( "MAX_PLAYERS", &pArgs );
		pArgs.clear();
	}
}
Example #5
0
int main(int argc, char *argv[])
{
	if(argc < 2){
		scprintf(_SC("SQDBG error : no file specified"));
		return -1;
	}

	// RVF +
	int debuggerPort = 0;
	for (int i = 1; i < argc; i++) {
		const char* arg = argv[i];
		if (!strncmp(arg, "-d", 2))
			debuggerPort = std::atoi(arg + 2);
	}

	if (!debuggerPort) {
		scprintf(_SC("SQDBG error : Debugger port not specified. Use the -d<PORT> parameter"));
		return EXIT_FAILURE;
	}
	// RVF -

	HSQUIRRELVM v = sq_open(1024);
	sqstd_seterrorhandlers(v);

	//!! INITIALIZES THE DEBUGGER ON THE TCP PORT 1234
	//!! ENABLES AUTOUPDATE
	HSQREMOTEDBG rdbg = sq_rdbg_init(v,debuggerPort,SQTrue);
	if(rdbg) {

		//!! ENABLES DEBUG INFO GENERATION(for the compiler)
		sq_enabledebuginfo(v,SQTrue);

		sq_setprintfunc(v,printfunc,errorfunc);

		//!! SUSPENDS THE APP UNTIL THE DEBUGGER CLIENT CONNECTS
		if(SQ_SUCCEEDED(sq_rdbg_waitforconnections(rdbg))) {
			scprintf(_SC("connected\n"));

			const SQChar *fname=NULL;
#ifdef _UNICODE
			SQChar sTemp[256];
			mbstowcs(sTemp,argv[argc-1],(int)strlen(argv[1])+1);
			fname=sTemp;
#else
			fname=argv[argc-1];
#endif 
			//!!REGISTERS STANDARDS LIBS
			sq_pushroottable(v);
			sqstd_register_bloblib(v);
			sqstd_register_iolib(v);
			sqstd_register_systemlib(v);
			sqstd_register_mathlib(v);
			sqstd_register_stringlib(v);
			//!!EXECUTE A SCTIPT
			if(SQ_FAILED(sqstd_dofile(v,fname,SQFalse,SQTrue))) {
				PrintError(v);
				_getch();
			}
		}
		//!! CLEANUP
		sq_rdbg_shutdown(rdbg);
	}
	else {
		PrintError(v);
	}
	sq_close(v);
	return 0;
}