コード例 #1
0
	/*
	 * invoke impact event
	 */
	static SQBool invokeImpactEvent(HSQUIRRELVM v, ContactPoint cp) {
		SQBool result = false;
		SQInteger top = sq_gettop(v);
		sq_pushroottable(v);
		sq_pushstring(v, "emo", -1);
		if (SQ_SUCCEEDED(sq_get(v, -2))) {
			sq_pushstring(v, "_onImpact", -1);
			if(SQ_SUCCEEDED(sq_get(v, -2))) {
				sq_pushroottable(v);
				sq_pushuserpointer(v, cp.fixtureA);
				sq_pushuserpointer(v, cp.fixtureB);
				sq_pushuserpointer(v, cp.fixtureA->GetBody());
				sq_pushuserpointer(v, cp.fixtureB->GetBody());
				pushVec2(v, cp.position);
				pushVec2(v, cp.normal);
				sq_pushfloat(v, cp.normalImpulse);
				sq_pushfloat(v, cp.tangentImpulse);

				result = SQ_SUCCEEDED(sq_call(v, 9, SQFalse, SQTrue));
			}
		}
		sq_settop(v,top);

		return result;
	}
コード例 #2
0
ファイル: VmFunc.cpp プロジェクト: pandazheng/emo-framework
/*
 * create a instance
 */
SQInteger createSQObject(HSQUIRRELVM v, 
				const char* package_name, const char* name,
				SQUserPointer ptr, SQRELEASEHOOK releaseHook) {
	sq_pushroottable(v);
	
	sq_pushstring(v, package_name, -1);
	if (!SQ_SUCCEEDED(sq_get(v, -2))) {
		sq_pop(v, 1);
		return 0;
	}
	if (name != NULL) {
		sq_pushstring(v, name, -1);
		if (!SQ_SUCCEEDED(sq_get(v, -2))) {
			sq_pop(v, 2);
			return 0;
		}
	}
	
	sq_createinstance(v, -1);
	sq_setinstanceup(v, -1, ptr);
	if (releaseHook != NULL) {
		sq_setreleasehook(v, -1, releaseHook);
	}
	sq_remove(v, -2);
	sq_remove(v, -2);

	return 1;
}
コード例 #3
0
ファイル: sqstdstream.cpp プロジェクト: Eiyeron/squirrel
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);
}
コード例 #4
0
ファイル: VmFunc.cpp プロジェクト: pandazheng/emo-framework
/*
 * Register member method with namespace
 * Must be called before loading script files
 */
void register_member_func_with_namespace(HSQUIRRELVM v, const char* nname, const char* cname, const char* fname, SQFUNCTION func) {
    sq_pushroottable(v);
    sq_pushstring(v, nname, -1);
    if(SQ_SUCCEEDED(sq_get(v, -2))) {
        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);
}
コード例 #5
0
ファイル: sqstdstream.cpp プロジェクト: Eiyeron/squirrel
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;
}
コード例 #6
0
ファイル: squirrel_helper.hpp プロジェクト: andrew889/OpenTTD
	inline SQInteger DefSQAdvancedNonStaticCallback(HSQUIRRELVM vm)
	{
		/* Find the amount of params we got */
		int nparam = sq_gettop(vm);
		SQUserPointer ptr = NULL;
		SQUserPointer real_instance = NULL;
		HSQOBJECT instance;

		/* Get the 'SQ' instance of this class */
		Squirrel::GetInstance(vm, &instance);

		/* Protect against calls to a non-static method in a static way */
		sq_pushroottable(vm);
		sq_pushstring(vm, OTTD2SQ(Tcls::GetClassName()), -1);
		sq_get(vm, -2);
		sq_pushobject(vm, instance);
		if (sq_instanceof(vm) != SQTrue) return sq_throwerror(vm, _SC("class method is non-static"));
		sq_pop(vm, 3);

		/* Get the 'real' instance of this class */
		sq_getinstanceup(vm, 1, &real_instance, 0);
		/* Get the real function pointer */
		sq_getuserdata(vm, nparam, &ptr, 0);
		if (real_instance == NULL) return sq_throwerror(vm, _SC("couldn't detect real instance of class for non-static call"));
		/* Remove the userdata from the stack */
		sq_pop(vm, 1);

		/* Call the function, which its only param is always the VM */
		return (SQInteger)(((Tcls *)real_instance)->*(*(Tmethod *)ptr))(vm);
	}
コード例 #7
0
ファイル: squirrel_helper.hpp プロジェクト: andrew889/OpenTTD
	inline SQInteger DefSQNonStaticCallback(HSQUIRRELVM vm)
	{
		/* Find the amount of params we got */
		int nparam = sq_gettop(vm);
		SQUserPointer ptr = NULL;
		SQUserPointer real_instance = NULL;
		HSQOBJECT instance;

		/* Get the 'SQ' instance of this class */
		Squirrel::GetInstance(vm, &instance);

		/* Protect against calls to a non-static method in a static way */
		sq_pushroottable(vm);
		sq_pushstring(vm, OTTD2SQ(Tcls::GetClassName()), -1);
		sq_get(vm, -2);
		sq_pushobject(vm, instance);
		if (sq_instanceof(vm) != SQTrue) return sq_throwerror(vm, _SC("class method is non-static"));
		sq_pop(vm, 3);

		/* Get the 'real' instance of this class */
		sq_getinstanceup(vm, 1, &real_instance, 0);
		/* Get the real function pointer */
		sq_getuserdata(vm, nparam, &ptr, 0);
		if (real_instance == NULL) return sq_throwerror(vm, _SC("couldn't detect real instance of class for non-static call"));
		/* Remove the userdata from the stack */
		sq_pop(vm, 1);

		try {
			/* Delegate it to a template that can handle this specific function */
			return HelperT<Tmethod>::SQCall((Tcls *)real_instance, *(Tmethod *)ptr, vm);
		} catch (SQInteger e) {
			sq_pop(vm, nparam);
			return e;
		}
	}
コード例 #8
0
ファイル: squirrel_util.cpp プロジェクト: CRS-ECHO51/supertux
bool has_float(HSQUIRRELVM vm, const char* name)
{
  sq_pushstring(vm, name, -1);
  if (SQ_FAILED(sq_get(vm, -2))) return false;
  sq_pop(vm, 1);
  return true;
}
コード例 #9
0
ファイル: CSquirrelVM.cpp プロジェクト: RAG20/IV-Network
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
}
コード例 #10
0
ファイル: squirrel.cpp プロジェクト: dolly22/openttd-sai
bool Squirrel::CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT *ret, int suspend)
{
	assert(!this->crashed);
	/* Store the stack-location for the return value. We need to
	 * restore this after saving or the stack will be corrupted
	 * if we're in the middle of a DoCommand. */
	SQInteger last_target = this->vm->_suspended_target;
	/* Store the current top */
	int top = sq_gettop(this->vm);
	/* Go to the instance-root */
	sq_pushobject(this->vm, instance);
	/* Find the function-name inside the script */
	sq_pushstring(this->vm, OTTD2SQ(method_name), -1);
	if (SQ_FAILED(sq_get(this->vm, -2))) {
		DEBUG(misc, 0, "[squirrel] Could not find '%s' in the class", method_name);
		sq_settop(this->vm, top);
		return false;
	}
	/* Call the method */
	sq_pushobject(this->vm, instance);
	if (SQ_FAILED(sq_call(this->vm, 1, ret == NULL ? SQFalse : SQTrue, SQTrue, suspend))) return false;
	if (ret != NULL) sq_getstackobj(vm, -1, ret);
	/* Reset the top, but don't do so for the AI main function, as we need
	 *  a correct stack when resuming. */
	if (suspend == -1 || !this->IsSuspended()) sq_settop(this->vm, top);
	/* Restore the return-value location. */
	this->vm->_suspended_target = last_target;

	return true;
}
コード例 #11
0
ファイル: sqtjsobj.cpp プロジェクト: shivanshs9/krkrz
/**
 * squirrel から吉里吉里オブジェクトを取得
 */
bool
TJSObject::getVariant(HSQUIRRELVM v, SQInteger idx, tTJSVariant *variant)
{
    if (sq_gettype(v, idx) == OT_CLASS) {
        if (idx < 0) {
            idx = sq_gettop(v) + 1 + idx;
        }
        bool ret = false;
        // クラス属性からオブジェクト情報を引き出す
        sq_pushnull(v);
        if (SQ_SUCCEEDED(sq_getattributes(v, idx))) {
            sq_pushstring(v, tjsClassAttrName, -1);
            if (SQ_SUCCEEDED(sq_get(v,-2))) {
                if (SQ_SUCCEEDED(sq_getvariant(v,-1, variant))) {
                    ret = true;
                }
                sq_pop(v,1);
            }
            sq_pop(v,1);
        } else {
            // XXX
            sq_pop(v,1);
        }
        return ret;
    } else if (sq_gettype(v, idx) == OT_INSTANCE) {
        TJSObject *obj = SQClassType<TJSObject>::getInstance(v, idx);
        if (obj && obj->instance.AsObjectClosureNoAddRef().IsValid(0, NULL, NULL, NULL) == TJS_S_TRUE) {
            *variant = obj->instance;
            return true;
        }
    }
    return false;
}
コード例 #12
0
int main()
{
	// 打开共享内存队列
	struct sq_head_t *sq = sq_open(0x1234); //shmkey=0x1234

	// 如果需要signal通知,需要向系统注册一个signal handler
	signal(SIGUSR1, siguser1);
	// 向队列注册我们的pid以便接收通知
	// 如果你的进程需要fork多个进程,一定好保证在sq_register_signal()调用之前进行
	int sigindex = sq_register_signal(sq);

	// 进入读循环
	while(1)
	{
		char buffer[1024];
         struct timeval write_time;
		int len = sq_get(sq, buffer, sizeof(buffer),&write_time);
		if(len<0) // 读失败
		{
		}
		else if(len==0) // 没有数据,继续做其它操作,然后等待,这里可以进入select/epoll_wait等待
		{
			sq_sigon(sq, sigindex); // 打开signal通知
			sleep(10);
			sq_sigoff(sq, sigindex); // 关闭signal通知
		}
		else // 收到数据了
		{
		   printf("sec %ds,usec%dus I am reader: %s\n",write_time.tv_sec,write_time.tv_usec,buffer);
		}
	}
    return 0;
}
コード例 #13
0
ファイル: sq_mysql.cpp プロジェクト: mingodad/squilu
static SQRESULT sq_mysql_result_row_as_table(HSQUIRRELVM v){
	SQ_FUNC_VARS(v);
	GET_mysql_result_INSTANCE();
	SQ_OPT_INTEGER(v, 2, row, -1);
    if(row < 0){
        sq_pushstring(v, _curr_row_key, -1);
        if(sq_get(v, 1) == SQ_OK){
            sq_getinteger(v, -1, &row);
        }
    }
    int row_count = dlmysql_num_rows(self);
    if(row < 0 || row >= row_count) return sq_throwerror(v, _SC("invalid row (" _PRINT_INT_FMT ")"), row);

    int col_count = dlmysql_num_fields(self);
    sq_newtableex(v, col_count);
    dlmysql_data_seek(self, row);
    const MYSQL_ROW res_row = dlmysql_fetch_row(self);
    unsigned long *lengths = dlmysql_fetch_lengths(self);
    MYSQL_FIELD *fields = dlmysql_fetch_fields(self);
    for(int i=0; i < col_count; ++i){
        sq_pushstring(v, fields[i].name, -1);
        sq_pushstring(v, (const SQChar*)res_row[i], lengths[i]);
        sq_rawset(v, -3);
    }
	return 1;
}
コード例 #14
0
ファイル: CScripts.cpp プロジェクト: Azon099/Five-Multiplayer
void CScripts::onBan(const char *szText)
{
	for(int i = 0; i < MAX_SCRIPTS; i++) {
		if(m_pScripts[i]) {
			// get the script vm pointer
			SQVM * pVM = m_pScripts[i]->GetVM();

			// Get the stack top
			int iTop = sq_gettop(pVM);

			// Push the root table onto the stack
			sq_pushroottable(pVM);

			// Push the function name onto the stack
			sq_pushstring(pVM, "onBan", -1);

			// Get the closure for the function
			if(SQ_SUCCEEDED(sq_get(pVM, -2))) {
				// Push the root table onto the stack
				sq_pushroottable(pVM);

				// Push the ban mask onto the stack
				sq_pushstring(pVM, szText, -1);

				// Call the function
				sq_call(pVM, 2, true, true);
			}

			// Restore the stack top
			sq_settop(pVM, iTop);
		}
	}
}
コード例 #15
0
ファイル: CScripts.cpp プロジェクト: Azon099/Five-Multiplayer
void CScripts::onTimerCreate(int timerId)
{
	for(int i = 0; i < MAX_SCRIPTS; i++) {
		if(m_pScripts[i]) {
			// get the script vm pointer
			SQVM * pVM = m_pScripts[i]->GetVM();

			// Get the stack top
			int iTop = sq_gettop(pVM);

			// Push the root table onto the stack
			sq_pushroottable(pVM);

			// Push the function name onto the stack
			sq_pushstring(pVM, "onTimerCreate", -1);

			// Get the closure for the function
			if(SQ_SUCCEEDED(sq_get(pVM, -2))) {
				// Push the root table onto the stack
				sq_pushroottable(pVM);

				// Push the timer id onto the stack
				sq_pushinteger(pVM, timerId);

				// Call the function
				sq_call(pVM, 2, true, true);
			}

			// Restore the stack top
			sq_settop(pVM, iTop);
		}
	}
}
コード例 #16
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;
}
コード例 #17
0
ファイル: CScripts.cpp プロジェクト: Azon099/Five-Multiplayer
void CScripts::Call(const char * szFunc, int iArgCount, SQObjectPtr * pArguments)
{
	for(int i = 0; i < MAX_SCRIPTS; i++) {
		if(m_pScripts[i]) {
			// get the script vm pointer
			SQVM * pVM = m_pScripts[i]->GetVM();

			// Get the stack top
			int iTop = sq_gettop(pVM);

			// Push the root table onto the stack
			sq_pushroottable(pVM);

			// Push the function name onto the stack
			sq_pushstring(pVM, szFunc, -1);

			if(SQ_SUCCEEDED(sq_get(pVM, -2))) {
				// Push the root table onto the stack
				sq_pushroottable(pVM);

				if(pArguments != NULL)
				{
					for(int j = 0; j < iArgCount; ++j)
						sq_pushobject(pVM, pArguments[j]);
						//pVM->Push(pArguments[j]);
				}
				sq_call(pVM, iArgCount + 1, true, true);

			}

			// Restore the stack top
			sq_settop(pVM, iTop);
		}
	}
}
コード例 #18
0
ファイル: sq_mysql.cpp プロジェクト: mingodad/squilu
static SQRESULT sq_mysql_exec_query(HSQUIRRELVM v){
	SQ_FUNC_VARS_NO_TOP(v);
	GET_mysql_INSTANCE();
    SQ_GET_STRING(v, 2, szSQL);

	if (dlmysql_real_query(self, szSQL, szSQL_size))
		/* error executing query */
		return sq_throwerror(v, _SC("error executing query. MySQL: %s"), dlmysql_error(self));

    MYSQL_RES *qres = dlmysql_store_result(self);

	sq_pushroottable(v);
	sq_pushstring(v, MySQL_Result_TAG, -1);
	if(sq_get(v, -2) == SQ_OK){
		if(sq_createinstance(v, -1) == SQ_OK){
			sq_setinstanceup(v, -1, qres);
			sq_setreleasehook(v, -1, sq_mysql_result_releasehook);
			sq_pushstring(v, _curr_row_key, -1);
			sq_pushinteger(v, -1);
			sq_set(v, -3);
			return 1;
		}
	}
    return SQ_ERROR;
}
コード例 #19
0
ファイル: CScripts.cpp プロジェクト: Tonyx97/vice-players
void CScripts::onInit(int iScript)
{
		if(m_pScripts[iScript]) {
			// get the script vm pointer
			SQVM * pVM = m_pScripts[iScript]->GetVM();

			// Get the stack top
			int iTop = sq_gettop(pVM);

			// Push the root table onto the stack
			sq_pushroottable(pVM);

			// Push the function name onto the stack
			sq_pushstring(pVM, "onInit", -1);

			// Get the closure for the function
			if(SQ_SUCCEEDED(sq_get(pVM, -2))) {
				// Push the root table onto the stack
				sq_pushroottable(pVM);

				// Call the function
				sq_call(pVM, 1, true, true);
			}

			// Restore the stack top
			sq_settop(pVM, iTop);
		}
}
コード例 #20
0
ファイル: sq_mysql.cpp プロジェクト: mingodad/squilu
static SQRESULT sq_mysql_result_col_value(HSQUIRRELVM v){
	SQ_FUNC_VARS_NO_TOP(v);
	GET_mysql_result_INSTANCE();
	SQObjectType ptype = sq_gettype(v, 2);
	int col = -1;
	if(ptype == OT_STRING){
	    SQ_GET_STRING(v, 2, col_name);
	    col = get_field_idx(self, col_name);
	}
	else
	{
	    SQ_GET_INTEGER(v, 2, idx);
	    col = idx;
	}
	if(col < 0) return sq_throwerror(v, _SC("invalid col index/name"));

    sq_pushstring(v, _curr_row_key, -1);
    if(sq_get(v, 1) == SQ_OK){
        SQ_GET_INTEGER(v, -1, curr_row);
        if(curr_row < dlmysql_num_rows(self)){
        	dlmysql_data_seek(self, curr_row);
        	const MYSQL_ROW res_row = dlmysql_fetch_row(self);
			unsigned long *lengths = dlmysql_fetch_lengths(self);
            sq_pushstring(v, (const SQChar*)res_row[col], lengths[col]);
            return 1;
        }
    }
	return SQ_ERROR;
}
コード例 #21
0
void BindInput()
{
	Sqrat::Class<CInput, Sqrat::NoConstructor> def;

	def.Func("KeyUp", &CInput::KeyUp);
	def.Func("KeyPressed", &CInput::KeyPressed);
	def.Func("KeyHeld", &CInput::KeyHeld);
	def.Func("KeyReleased", &CInput::KeyReleased);
		
	Sqrat::RootTable().Bind("InputSystem", def);
	
	//Sqrat::ConstTable().Const("KEY_LEFT", KEY_LEFT);
	MAKE_KEY( KEY_LEFT );
	MAKE_KEY( KEY_RIGHT );
	MAKE_KEY( KEY_UP );
	MAKE_KEY( KEY_DOWN );
	MAKE_KEY( KEY_Q );
	MAKE_KEY( KEY_W );
	MAKE_KEY( KEY_PAGEUP );
	MAKE_KEY( KEY_PAGEDOWN );
	MAKE_KEY( KEY_HOME );

	// Push the singleton to squirrel
	sq_pushroottable( Sqrat::DefaultVM::Get() );
	sq_pushstring( Sqrat::DefaultVM::Get(), "InputSystem", -1 );
	sq_get(  Sqrat::DefaultVM::Get(), -2 );
	sq_pushstring(  Sqrat::DefaultVM::Get(), "Input", -1 );
	sq_createinstance(  Sqrat::DefaultVM::Get(), -2 );
	sq_setinstanceup(  Sqrat::DefaultVM::Get(), -1, (SQUserPointer)Input() );
	sq_newslot(  Sqrat::DefaultVM::Get(), -4, SQFalse );
	sq_pop(  Sqrat::DefaultVM::Get(), 2 );
}
コード例 #22
0
ファイル: VmFunc.cpp プロジェクト: pandazheng/emo-framework
/*
 * Call Squirrel function with no parameter
 * Returns SQTrue if sq_call succeeds.
 */
SQBool callSqFunction(HSQUIRRELVM v, const SQChar* nname, const SQChar* name) {
	SQBool result = SQFalse;

	SQInteger top = sq_gettop(v);
	sq_pushroottable(v);
	sq_pushstring(v, nname, -1);
	if (SQ_SUCCEEDED(sq_get(v, -2))) {
		sq_pushstring(v, name, -1);
		if(SQ_SUCCEEDED(sq_get(v, -2))) {
			sq_pushroottable(v);
			result = SQ_SUCCEEDED(sq_call(v, 1, SQFalse, SQTrue));
		}
		sq_settop(v,top);
	}
	
	return result;
}
コード例 #23
0
SQInteger ScriptText::_SetParam(int parameter, HSQUIRRELVM vm)
{
	if (parameter >= SCRIPT_TEXT_MAX_PARAMETERS) return SQ_ERROR;

	free(this->params[parameter]);
	if (this->paramt[parameter] != NULL) this->paramt[parameter]->Release();

	this->parami[parameter] = 0;
	this->params[parameter] = NULL;
	this->paramt[parameter] = NULL;

	switch (sq_gettype(vm, -1)) {
		case OT_STRING: {
			const SQChar *value;
			sq_getstring(vm, -1, &value);

			this->params[parameter] = strdup(SQ2OTTD(value));
			break;
		}

		case OT_INTEGER: {
			SQInteger value;
			sq_getinteger(vm, -1, &value);

			this->parami[parameter] = value;
			break;
		}

		case OT_INSTANCE: {
			SQUserPointer real_instance = NULL;
			HSQOBJECT instance;

			sq_getstackobj(vm, -1, &instance);

			/* Validate if it is a GSText instance */
			sq_pushroottable(vm);
			sq_pushstring(vm, _SC("GSText"), -1);
			sq_get(vm, -2);
			sq_pushobject(vm, instance);
			if (sq_instanceof(vm) != SQTrue) return SQ_ERROR;
			sq_pop(vm, 3);

			/* Get the 'real' instance of this class */
			sq_getinstanceup(vm, -1, &real_instance, 0);
			if (real_instance == NULL) return SQ_ERROR;

			ScriptText *value = static_cast<ScriptText *>(real_instance);
			value->AddRef();
			this->paramt[parameter] = value;
			break;
		}

		default: return SQ_ERROR;
	}

	if (this->paramc <= parameter) this->paramc = parameter + 1;
	return 0;
}
コード例 #24
0
static void call(HSQUIRRELVM v, const wgChar *devicename)
{
	sq_pushroottable(v);
	sq_pushstring(v, _SC("flash_device_get"), -1);
	if(SQ_SUCCEEDED(sq_get(v,-2))){
		sq_pushroottable(v);
		sq_pushstring(v, devicename, -1);
		sq_call(v, 2, SQTrue, SQTrue);
	}
}
コード例 #25
0
ファイル: SquirrelObject.cpp プロジェクト: henryrao/kdguigl
BOOL SquirrelObject::GetSlot(int key) /*const*/
{
	sq_pushobject(m_Vm.GetVMPtr(),_o);
	sq_pushinteger(m_Vm.GetVMPtr(),key);
	if(SQ_SUCCEEDED(sq_get(m_Vm.GetVMPtr(),-2))) {
		return TRUE;
	}
	
	return FALSE;
}
コード例 #26
0
ファイル: SquirrelObject.cpp プロジェクト: henryrao/kdguigl
BOOL SquirrelObject::GetSlot(const SQChar *name) /*const*/
{
	sq_pushobject(m_Vm.GetVMPtr(),_o);
	sq_pushstring(m_Vm.GetVMPtr(),name,-1);
	if(SQ_SUCCEEDED(sq_get(m_Vm.GetVMPtr(),-2))) {
		return TRUE;
	}
	
	return FALSE;
}
コード例 #27
0
ファイル: VmFunc.cpp プロジェクト: pandazheng/emo-framework
/*
 * Register new table with namespace.
 * Must be called before loading script files
 */
void register_table_with_namespace(HSQUIRRELVM v, const char *nname, const char *tname) {
    sq_pushroottable(v);
    sq_pushstring(v, nname, -1);
    if(SQ_SUCCEEDED(sq_get(v, -2))) {
        sq_pushstring(v, tname, -1);
        sq_newtable(v);
        sq_createslot(v, -3);
    }
    sq_pop(v, 1);
}
コード例 #28
0
ファイル: VmFunc.cpp プロジェクト: pandazheng/emo-framework
/*
 * get instance member value as table
 */
bool getInstanceMemberAsTable(HSQUIRRELVM v, int idx, const char *cname, const char *name, SQFloat* value) {
	if (sq_gettype(v, idx) == OT_NULL) return false;
	sq_pushstring(v, cname, -1);
	if (!SQ_SUCCEEDED(sq_get(v, idx))) {
		sq_pop(v, 1);
		return false;
	}
	sq_pushstring(v, name, -1);
	if (!SQ_SUCCEEDED(sq_get(v, -2))) {
		sq_pop(v, 1);
		return false;
	}
	if (sq_gettype(v, -1) == OT_NULL) {
		sq_pop(v, 1);
		return false;
	}
	sq_getfloat(v, -1, value);
	sq_pop(v, 1);
	return true;
}
コード例 #29
0
ファイル: VmFunc.cpp プロジェクト: pandazheng/emo-framework
/*
 * Call Squirrel function with one float parameter
 * Returns SQTrue if sq_call succeeds.
 */
SQBool callSqFunction_Bool_Float(HSQUIRRELVM v, const SQChar* nname, const SQChar* name, SQFloat value, SQBool defaultValue) {
	SQBool   result = SQFalse;

	SQInteger top = sq_gettop(v);
	sq_pushroottable(v);
	sq_pushstring(v, nname, -1);
	if (SQ_SUCCEEDED(sq_get(v, -2))) {
		sq_pushstring(v, name, -1);
		if(SQ_SUCCEEDED(sq_get(v, -2))) {
			sq_pushroottable(v);
			sq_pushfloat(v, value);
			if (SQ_SUCCEEDED(sq_call(v, 2, SQTrue, SQTrue))) {
				sq_getbool(v, sq_gettop(v), &result);
			}
		}
	}
	sq_settop(v,top);

	return result;
}
コード例 #30
0
ファイル: sq_mysql.cpp プロジェクト: mingodad/squilu
static SQRESULT sq_mysql_result_eof(HSQUIRRELVM v){
	SQ_FUNC_VARS_NO_TOP(v);
	GET_mysql_result_INSTANCE();
    sq_pushstring(v, _curr_row_key, -1);
    if(sq_get(v, 1) == SQ_OK){
        SQ_GET_INTEGER(v, -1, curr_row);
        sq_pushbool(v, curr_row < dlmysql_num_rows(self));
    }
	else sq_pushbool(v, SQTrue);
	return 1;
}