Esempio n. 1
0
    // プロパティ登録
    void registerProperty(const tjs_char *propertyName, tTJSVariant &property, bool staticMember) {

        ttstr name = L"set";
        name += toupper(*propertyName);
        name += (propertyName + 1);
        sq_pushstring(v, name.c_str(), -1);
        sq_pushvariant(v, property);
        if (staticMember) {
            sq_pushvariant(v, tjsClassObj);
            sq_newclosure(v, TJSObject::tjsStaticSetter, 2);
            sq_newslot(v, -3, SQTrue);
        } else {
            sq_newclosure(v, TJSObject::tjsSetter, 1);
            sq_newslot(v, -3, SQFalse);
        }

        name = L"get";
        name += toupper(*propertyName);
        name += (propertyName + 1);
        sq_pushstring(v, name.c_str(), -1);
        sq_pushvariant(v, property);
        if (staticMember) {
            sq_pushvariant(v, tjsClassObj);
            sq_newclosure(v, TJSObject::tjsStaticGetter, 2);
            sq_newslot(v, -3, SQTrue);
        } else {
            sq_newclosure(v, TJSObject::tjsGetter, 1);
            sq_newslot(v, -3, SQFalse);
        }
    }
Esempio n. 2
0
SQInteger sqstd_register_stringlib( HSQUIRRELVM v ) {
	sq_pushstring( v, _SC( "regexp" ), -1 );
	sq_newclass( v, SQFalse );
	SQInteger i = 0;
	while ( rexobj_funcs[i].name != 0 ) {
		SQRegFunction &f = rexobj_funcs[i];
		sq_pushstring( v, f.name, -1 );
		sq_newclosure( v, f.f, 0 );
		sq_setparamscheck( v, f.nparamscheck, f.typemask );
		sq_setnativeclosurename( v, -1, f.name );
		sq_createslot( v, -3 );
		i++;
	}
	sq_createslot( v, -3 );

	i = 0;
	while ( stringlib_funcs[i].name != 0 ) {
		sq_pushstring( v, stringlib_funcs[i].name, -1 );
		sq_newclosure( v, stringlib_funcs[i].f, 0 );
		sq_setparamscheck( v, stringlib_funcs[i].nparamscheck, stringlib_funcs[i].typemask );
		sq_setnativeclosurename( v, -1, stringlib_funcs[i].name );
		sq_createslot( v, -3 );
		i++;
	}
	return 1;
}
Esempio n. 3
0
HSQOBJECT class_init(HSQUIRRELVM v,SQFUNCTION c,const SQChar * p_name)
{	
	HSQOBJECT class_id;
	sq_pushroottable(v);
	sq_pushstring(v,p_name,-1);

	sq_newclass(v,SQFalse);
	sq_getstackobj(v,-1,&class_id);		
	sq_settypetag(v,-1,&class_id);		

	HSQOBJECT string_constructor;
	sq_pushstring(v,_SC("constructor"),-1);
	sq_resetobject(&string_constructor);
	sq_getstackobj(v,-1,&string_constructor);
	sq_newclosure(v,c,0);
	sq_newslot(v,-3,false);
		
	sq_pushstring(v,_SC("_cloned"),-1);
	sq_newclosure(v,clone<T>,0);
	sq_newslot(v,-3,false);
		
	sq_newslot(v,-3,false);
	sq_pop(v,1);

	return class_id;
}
Esempio n. 4
0
void CSquirrelVM::BeginRegisterScriptClass(const char* className, scriptFunction pfnFunction, void* userPointer, const char* baseClass)
{

	iFuncIndex = 0;
#if 1
	int n = 0;
	oldtop = sq_gettop(m_pVM);
	sq_pushroottable(m_pVM);
	sq_pushstring(m_pVM, className, -1);

	if(baseClass) {
		sq_pushstring(m_pVM, baseClass, -1);
		if(SQ_FAILED(sq_get(m_pVM, -3))) { // make sure base exists
			sq_settop(m_pVM, oldtop);
			return;
		}
	}
	if(SQ_FAILED(sq_newclass(m_pVM, baseClass ? 1 : 0))) {
		sq_settop(m_pVM, oldtop);
		return;
	}

	sq_pushstring(m_pVM, _SC("constructor"), -1);
	if (userPointer != nullptr)
	{
		sq_pushuserpointer(m_pVM, userPointer);
		sq_newclosure(m_pVM, (SQFUNCTION) pfnFunction, 1);
	}
	else
		sq_newclosure(m_pVM, (SQFUNCTION)pfnFunction, 0);
	sq_newslot(m_pVM, -3, false); // Add the constructor method
#endif
}
bool SquirrelScriptContext::RegisterUserClass(ClassDesc* desc)
{
	MultiScriptAssert(desc->m_constructor);
	MultiScriptAssert(desc->m_destructor);

	SquirrelClassInfo* classInfo = new SquirrelClassInfo();
	classInfo->m_desc = desc;
	classInfo->m_context = this;

	// Create class
	sq_pushstring(m_vm, desc->m_name, -1);

	// TODO: Handle subclass via 2nd parameter
	sq_newclass(m_vm, SQFalse);

	// Add methods
	for (unsigned int i = 0; i < desc->m_methods.size(); ++i)
	{
		sq_pushstring(m_vm, desc->m_methods[i].m_name, -1);
		sq_pushuserpointer(m_vm, classInfo);
		sq_pushinteger(m_vm, i);
		sq_newclosure(m_vm, SquirrelClassMethodCallback, 2);
		sq_createslot(m_vm, -3);
	}

	// Add constructor
	sq_pushstring(m_vm, "constructor", -1);
	sq_pushuserpointer(m_vm, classInfo);
	sq_newclosure(m_vm, SquirrelClassConstructorCallback, 1);
	sq_createslot(m_vm, -3);

	// Add to-string method
	sq_pushstring(m_vm, "AsString", -1);
	sq_pushuserpointer(m_vm, classInfo);
	sq_newclosure(m_vm, SquirrelClassToStringMethodCallback, 1);
	sq_createslot(m_vm, -3);

	// Add optional destructor
	if (!desc->m_garbageCollect)
	{
		// Add destructor
		sq_pushstring(m_vm, "Destroy", -1);
		sq_pushuserpointer(m_vm, classInfo);
		sq_newclosure(m_vm, SquirrelClassDestructorCallback, 1);
		sq_createslot(m_vm, -3);
	}
	else
	{
		// TODO: Add garbage collection callback here
	}

	// Add class to root table
	sq_createslot(m_vm, -3);

	// Add class info
	m_classes.push_back(classInfo);
	return true;
}
Esempio n. 6
0
SQInteger sqstd_register_stringlib(HSQUIRRELVM v)
{
	sq_pushstring(v,_SC("regexp"),-1);
	sq_newclass(v,SQFalse,"regexp");
	SQInteger i = 0;
	while(rexobj_funcs[i].name != 0) {
		SQRegFunction &f = rexobj_funcs[i];
		sq_pushstring(v,f.name,-1);
		sq_newclosure(v,f.f,0);
		sq_setparamscheck(v,f.nparamscheck,f.typemask);
		sq_setnativeclosureinfo(v,-1,f.name,f.file);
		if (f.help)
		{
			sq_pushstring(v,f.help,-1);
			sq_sethelp(v, -2);
		}
		sq_createslot(v,-3);
		i++;
	}
	sq_createslot(v,-3);

	i = 0;
	while(stringlib_funcs[i].name!=0)
	{
		sq_pushstring(v,stringlib_funcs[i].name,-1);
		sq_newclosure(v,stringlib_funcs[i].f,0);
		sq_setparamscheck(v,stringlib_funcs[i].nparamscheck,stringlib_funcs[i].typemask);
		sq_setnativeclosureinfo(v,-1,stringlib_funcs[i].name,stringlib_funcs[i].file);
		if (stringlib_funcs[i].help)
		{
			sq_pushstring(v,stringlib_funcs[i].help,-1);
			sq_sethelp(v, -2);
		}
		sq_createslot(v,-3);
		i++;
	}

	sq_getdefaultdelegate(v, OT_STRING);
	i = 0;
	while(stringextdeleg_funcs[i].name!=0)
	{
		sq_pushstring(v,stringextdeleg_funcs[i].name,-1);
		sq_newclosure(v,stringextdeleg_funcs[i].f,0);
		sq_setparamscheck(v,stringextdeleg_funcs[i].nparamscheck,stringextdeleg_funcs[i].typemask);
		sq_setnativeclosureinfo(v,-1,stringextdeleg_funcs[i].name,stringextdeleg_funcs[i].file);
		if (stringextdeleg_funcs[i].help)
		{
			sq_pushstring(v,stringextdeleg_funcs[i].help,-1);
			sq_sethelp(v,-2);
		}
		sq_createslot(v,-3);
		i++;
	}
	sq_pop(v, 1);
	return 1;
}
bool SQDbgServer::Init()
{
	//creates  an environment table for the debugger
	
	sq_newtable(_v);
	sq_getstackobj(_v,-1,&_debugroot);
	sq_addref(_v,&_debugroot);

	//creates a emptyslot to store the watches
	sq_pushstring(_v,_SC("watches"),-1);
	sq_pushnull(_v);
	sq_createslot(_v,-3);

	sq_pushstring(_v,_SC("beginelement"),-1);
	sq_pushuserpointer(_v,this);
	sq_newclosure(_v,beginelement,1);
	sq_setparamscheck(_v,2,_SC(".s"));
	sq_createslot(_v,-3);

	sq_pushstring(_v,_SC("endelement"),-1);
	sq_pushuserpointer(_v,this);
	sq_newclosure(_v,endelement,1);
	sq_setparamscheck(_v,2,_SC(".s"));
	sq_createslot(_v,-3);

	sq_pushstring(_v,_SC("attribute"),-1);
	sq_pushuserpointer(_v,this);
	sq_newclosure(_v,attribute,1);
	sq_setparamscheck(_v,3,_SC(".ss"));
	sq_createslot(_v,-3);

	sq_pop(_v,1);

	//stores debug hook and error handler in the registry
	sq_pushregistrytable(_v);

	sq_pushstring(_v,SQDBG_DEBUG_HOOK,-1);
	sq_pushuserpointer(_v,this);
	sq_newclosure(_v,debug_hook,1);
	sq_createslot(_v,-3);
	
	sq_pushstring(_v,SQDBG_ERROR_HANDLER,-1);
	sq_pushuserpointer(_v,this);
	sq_newclosure(_v,error_handler,1);
	sq_createslot(_v,-3);

	
	sq_pop(_v,1);

	//sets the error handlers
	SetErrorHandlers();
	return true;
}
Esempio n. 8
0
 // ファンクション登録
 void registerFunction(const tjs_char *functionName, tTJSVariant &function, bool staticMember) {
     sq_pushstring(v, functionName, -1);
     sq_pushvariant(v, function);
     if (staticMember) {
         sq_pushvariant(v, tjsClassObj);
         sq_newclosure(v, TJSObject::tjsStaticInvoker, 2);
         sq_newslot(v, -3, SQTrue);
     } else {
         sq_newclosure(v, TJSObject::tjsInvoker, 1);
         sq_newslot(v, -3, SQFalse);
     }
 }
Esempio n. 9
0
SQRESULT declare_stream(HSQUIRRELVM v,const SQChar* name,SQUserPointer typetag,const SQChar* reg_name,const SQRegFunction *methods,const SQRegFunction *globals)
{
    if(sq_gettype(v,-1) != OT_TABLE)
        return sq_throwerror(v,_SC("table expected"));
    SQInteger top = sq_gettop(v);
    //create delegate
    init_streamclass(v);
    sq_pushregistrytable(v);
    sq_pushstring(v,reg_name,-1);
    sq_pushstring(v,_SC("std_stream"),-1);
    if(SQ_SUCCEEDED(sq_get(v,-3))) {
        sq_newclass(v,SQTrue);
        sq_settypetag(v,-1,typetag);
        SQInteger i = 0;
        while(methods[i].name != 0) {
            const SQRegFunction &f = methods[i];
            sq_pushstring(v,f.name,-1);
            sq_newclosure(v,f.f,0);
            sq_setparamscheck(v,f.nparamscheck,f.typemask);
            sq_setnativeclosurename(v,-1,f.name);
            sq_newslot(v,-3,SQFalse);
            i++;
        }
        sq_newslot(v,-3,SQFalse);
        sq_pop(v,1);

        i = 0;
        while(globals[i].name!=0)
        {
            const SQRegFunction &f = globals[i];
            sq_pushstring(v,f.name,-1);
            sq_newclosure(v,f.f,0);
            sq_setparamscheck(v,f.nparamscheck,f.typemask);
            sq_setnativeclosurename(v,-1,f.name);
            sq_newslot(v,-3,SQFalse);
            i++;
        }
        //register the class in the target table
        sq_pushstring(v,name,-1);
        sq_pushregistrytable(v);
        sq_pushstring(v,reg_name,-1);
        sq_get(v,-2);
        sq_remove(v,-2);
        sq_newslot(v,-3,SQFalse);

        sq_settop(v,top);
        return SQ_OK;
    }
    sq_settop(v,top);
    return SQ_ERROR;
}
Esempio n. 10
0
BOOL SbuCreateStaticNamespace(HSQUIRRELVM v,ScriptNamespaceDecl *sn)
{
	int n = 0;
	sq_pushroottable(v);
	sq_pushstring(v,sn->name,-1);
	sq_newtable(v);
	const ScriptClassMemberDecl *members = sn->members;
	const ScriptClassMemberDecl *m = NULL;
	while(members[n].name) {
		m = &members[n];
		sq_pushstring(v,m->name,-1);
		sq_newclosure(v,m->func,0);
		sq_setparamscheck(v,m->params,m->typemask);
		sq_setnativeclosurename(v,-1,m->name);
		sq_createslot(v,-3);
		n++;
	}
	const ScriptConstantDecl *consts = sn->constants;
	const ScriptConstantDecl *c = NULL;
	n = 0;
	while(consts[n].name) {
		c = &consts[n];
		sq_pushstring(v,c->name,-1);
		switch(c->type) {
		case OT_STRING: sq_pushstring(v,c->val.s,-1);break;
		case OT_INTEGER: sq_pushinteger(v,c->val.i);break;
		case OT_FLOAT: sq_pushfloat(v,c->val.f);break;
		}
		sq_createslot(v,-3);
		n++;
	}
	if(sn->delegate) {
		const ScriptClassMemberDecl *members = sn->delegate;
		const ScriptClassMemberDecl *m = NULL;
		sq_newtable(v);
		while(members[n].name) {
			m = &members[n];
			sq_pushstring(v,m->name,-1);
			sq_newclosure(v,m->func,0);
			sq_setparamscheck(v,m->params,m->typemask);
			sq_setnativeclosurename(v,-1,m->name);
			sq_createslot(v,-3);
			n++;
		}
		sq_setdelegate(v,-2);
	}
	sq_createslot(v,-3);
	sq_pop(v,1);
	
	return TRUE;
}
Esempio n. 11
0
SQInteger sqlang_register_global_func(HSQUIRRELVM J, SQFUNCTION f, char *fname)
{
    sq_pushstring(J, fname, -1);
    sq_newclosure(J, f, 0); /* create a new function */
    sq_newslot(J, -3, SQFalse);
    return 0;
}
Esempio n. 12
0
void Sq_RegisterFunc(HSQUIRRELVM v,SQFUNCTION f,const char *fname, int ParamNum, const char *params) {
  sq_pushstring(v,fname,-1);
  sq_newclosure(v,f,0);
  sq_newslot(v,-3,SQFalse);
  if(params)
    sq_setparamscheck(v, ParamNum, _SC(params)); 
}
Esempio n. 13
0
/*
 * Register global function.
 * Must be called before loading script files
 */
void register_global_func(HSQUIRRELVM v, SQFUNCTION func, const char *fname) {
    sq_pushroottable(v);
    sq_pushstring(v, fname, -1);
    sq_newclosure(v, func, 0);
    sq_createslot(v, -3);
    sq_pop(v,1);
}
Esempio n. 14
0
void init_streamclass(HSQUIRRELVM v)
{
    sq_pushregistrytable(v);
    sq_pushstring(v,_SC("std_stream"),-1);
    if(SQ_FAILED(sq_get(v,-2))) {
        sq_pushstring(v,_SC("std_stream"),-1);
        sq_newclass(v,SQFalse);
        sq_settypetag(v,-1,(SQUserPointer)SQSTD_STREAM_TYPE_TAG);
        SQInteger i = 0;
        while(_stream_methods[i].name != 0) {
            const SQRegFunction &f = _stream_methods[i];
            sq_pushstring(v,f.name,-1);
            sq_newclosure(v,f.f,0);
            sq_setparamscheck(v,f.nparamscheck,f.typemask);
            sq_newslot(v,-3,SQFalse);
            i++;
        }
        sq_newslot(v,-3,SQFalse);
        sq_pushroottable(v);
        sq_pushstring(v,_SC("stream"),-1);
        sq_pushstring(v,_SC("std_stream"),-1);
        sq_get(v,-4);
        sq_newslot(v,-3,SQFalse);
        sq_pop(v,1);
    }
    else {
        sq_pop(v,1); //result
    }
    sq_pop(v,1);
}
Esempio n. 15
0
void SqEnv::_init(size_t sz)
{

   // AutoLock a(&_m);
    __vm = sq_open(sz);
    _vm= &__vm;

    assert( *_vm );

    Sqrat::DefaultVM::Set(*_vm);
    sq_setprintfunc(*_vm, SqEnv::print_func, SqEnv::print_func);
    sq_newclosure(*_vm, SqEnv::error_handler,0);
    sq_seterrorhandler(*_vm);
    //sq
    sq_pushroottable(*_vm);
    sqstd_register_iolib(*_vm);
    sqstd_register_bloblib(*_vm);
    sqstd_register_mathlib(*_vm);
    sqstd_register_stringlib(*_vm);
    sqstd_register_systemlib(*_vm);

    sqstd_seterrorhandlers(*_vm);
    sqstd_printcallstack(*_vm);

//    setnativedebughook(_vmsys,debug_hook);
    sq_notifyallexceptions(*_vm, true);
}
Esempio n. 16
0
void sq_base_register(HSQUIRRELVM v)
{
	SQInteger i=0;
	sq_pushroottable(v);
	while(base_funcs[i].name!=0) {
		sq_pushstring(v,base_funcs[i].name,-1);
		sq_newclosure(v,base_funcs[i].f,0);
		sq_setnativeclosurename(v,-1,base_funcs[i].name);
		sq_setparamscheck(v,base_funcs[i].nparamscheck,base_funcs[i].typemask);
		sq_createslot(v,-3);
		i++;
	}
	sq_pushstring(v,_SC("_version_"),-1);
	sq_pushstring(v,SQUIRREL_VERSION,-1);
	sq_createslot(v,-3);
	sq_pushstring(v,_SC("_charsize_"),-1);
	sq_pushinteger(v,sizeof(SQChar));
	sq_createslot(v,-3);
	sq_pushstring(v,_SC("_intsize_"),-1);
	sq_pushinteger(v,sizeof(SQInteger));
	sq_createslot(v,-3);
	sq_pushstring(v,_SC("_floatsize_"),-1);
	sq_pushinteger(v,sizeof(SQFloat));
	sq_createslot(v,-3);
	sq_pop(v,1);
}
Esempio n. 17
0
BOOL SbuCreateClass(HSQUIRRELVM v,SquirrelClassDecl *cd)
{
	int n = 0;
	int oldtop = sq_gettop(v);
	sq_pushroottable(v);
	sq_pushstring(v,cd->name,-1);
	if(cd->base) {
		sq_pushstring(v,cd->base,-1);
		if(SQ_FAILED(sq_get(v,-3))) {
			sq_settop(v,oldtop);
			return FALSE;
		}
	}
	if(SQ_FAILED(sq_newclass(v,cd->base?1:0))) {
		sq_settop(v,oldtop);
		return FALSE;
	}
	sq_settypetag(v,-1,(SQUserPointer)cd);
	const ScriptClassMemberDecl *members = cd->members;
	const ScriptClassMemberDecl *m = NULL;
	while(members[n].name) {
		m = &members[n];
		sq_pushstring(v,m->name,-1);
		sq_newclosure(v,m->func,0);
		sq_setparamscheck(v,m->params,m->typemask);
		sq_setnativeclosurename(v,-1,m->name);
		sq_createslot(v,-3);
		n++;
	}
	sq_createslot(v,-3);
	sq_pop(v,1);
	return TRUE;
}
Esempio n. 18
0
void CSquirrel::RegisterFunction(const char * szFunctionName, SQFUNCTION pfnFunction, int iParameterCount, const char * szFunctionTemplate, bool bPushRootTable)
{
	// Push the root table onto the stack if needed
	if(bPushRootTable)
		sq_pushroottable(m_pVM);

	// Push the function name onto the stack
	sq_pushstring(m_pVM, szFunctionName, -1);

	// Create a new function
	sq_newclosure(m_pVM, pfnFunction, 0);

	// Set the function parameter template and count
	if(iParameterCount != -1)
	{
		char szTemp[128];

		if(szFunctionTemplate)
			sprintf(szTemp, ".%s", szFunctionTemplate);

		sq_setparamscheck(m_pVM, (iParameterCount + 1), (szFunctionTemplate) ? szTemp : NULL);
	}

	// Create a new slot
	sq_createslot(m_pVM, -3);

	// Pop the root table from the stack if needed
	if(bPushRootTable)
		sq_pop(m_pVM, 1);
}
Esempio n. 19
0
void sqstd_seterrorhandlers(HSQUIRRELVM v)
{
	sq_setcompilererrorhandler(v,_sqstd_compiler_error);
	sq_newclosure(v,_sqstd_aux_printerror,0);
	sq_seterrorhandler(v);

	// additional functions
	sq_pushroottable(v);
	sq_pushstring(v, _SC("printCallStack"), -1);
	sq_newclosure(v, printCallStack, 0);
	sq_createslot(v, -3);
	sq_pushstring(v, _SC("notifyAllExceptions"), -1);
	sq_newclosure(v, notifyAllExceptions, 0);
	sq_setparamscheck(v, 2, _SC(".n|b"));
	sq_createslot(v, -3);
	sq_pop(v,1);
}
Esempio n. 20
0
SQInteger register_global_func(HSQUIRRELVM& v,SQFUNCTION f,const char *fname)
{
	sq_pushroottable(v);
	sq_pushstring(v,fname,-1);
	sq_newclosure(v,f,0);
	sq_newslot(v,-3,SQFalse);
	sq_pop(v,1);
}
Esempio n. 21
0
SQInteger register_member_func(HSQUIRRELVM& v,SQFUNCTION f,const char *fname,HSQOBJECT id)
{
	sq_pushobject(v,id);
	sq_pushstring(v,fname,-1);
	sq_newclosure(v,f,0);
	sq_newslot(v,-3,SQFalse);
	sq_pop(v,1);
}
Esempio n. 22
0
void register_global(HSQUIRRELVM v,SQFUNCTION f,const char *fname)
{
    sq_pushroottable(v);
    sq_pushstring(v,fname,-1);
    sq_newclosure(v,f,0); //create a new function
    sq_createslot(v,-3);
    sq_pop(v,1); //pops the root table
}
Esempio n. 23
0
void setGlobalFunction(HSQUIRRELVM vm, const char * name, SQFUNCTION cb_func)
{
    sq_pushroottable(vm);
    sq_pushstring(vm, name, -1);
    sq_newclosure(vm, cb_func, 0);
    sq_newslot(vm, -3, false);
    sq_pop(vm, 1); // pop roottable
}
Esempio n. 24
0
void RegisterFunction(HSQUIRRELVM pVM, const char * szName, SQFUNCTION pfnFunction)
{
	sq_pushroottable(pVM);
	sq_pushstring(pVM, szName, -1);
	sq_newclosure(pVM, pfnFunction, 0);
	sq_createslot(pVM, -3);
	sq_pop(pVM, 1);
}
Esempio n. 25
0
SquirrelObject SquirrelVM::CreateFunction(SQFUNCTION func)
{
	SquirrelObject ret(_VM);
	sq_newclosure(_VM,func,0);
	ret.AttachToStackObject(-1);
	sq_pop(_VM,1);
	return ret;
}
Esempio n. 26
0
SQInteger SbuRegisterGlobalFunc(HSQUIRRELVM v, SQFUNCTION f, const SQChar* fname)
{
    sq_pushroottable(v);
    sq_pushstring(v,fname,-1);
    sq_newclosure(v,f,0); //create a new function
    sq_newslot(v,-3,SQFalse); 
    sq_pop(v,1); //pops the root table  
    return 0;
}
Esempio n. 27
0
/*
 * Register member method.
 * Must be called before loading script files
 */
void register_member_func(HSQUIRRELVM v, const char* cname, const char* fname, SQFUNCTION func) {
    sq_pushroottable(v);
    sq_pushstring(v, cname, -1);
    if(SQ_SUCCEEDED(sq_get(v, -2))) {
        sq_pushstring(v, fname, -1);
        sq_newclosure(v, func, 0);
        sq_newslot(v, -3, true);
    }
    sq_pop(v, 1);
}
Esempio n. 28
0
SQRESULT sqrat_register_importlib(HSQUIRRELVM v) {
    sq_pushroottable(v);

    sq_pushstring(v, _SC("import"), -1);
    sq_newclosure(v, &sqratbase_import, 0);
    sq_newslot(v, -3, 0);

    sq_pop(v, 1); // pop sqrat table

    return SQ_OK;
}
Esempio n. 29
0
MTR_DCLSPC void MTR_CALL MTR_ScriptsRegisterFunction(SQFUNCTION func,
 const char * funcname)
{
    sq_pushroottable(mtrVm);
    sq_pushstring(mtrVm, funcname, -1);
    sq_newclosure(mtrVm, func, 0); //create a new function
    sq_newslot(mtrVm, -3, SQFalse);
    sq_pop(mtrVm, 1); //pops the root table
    MTR_LogWrite_s("Script function added:", 3, MTR_LMT_INFO, funcname);
    return;
}
Esempio n. 30
0
void RegisterFunction(HSQUIRRELVM pVM, char * szFunc, SQFUNCTION func, int params, const char * szTemplate)
{
    sq_pushroottable(pVM);

    sq_pushstring(pVM, szFunc, -1);
    sq_newclosure(pVM, func, 0);
    if(params != -1)
    {
        sq_setparamscheck(pVM, params, szTemplate);
    }
    sq_createslot(pVM, -3);
}