예제 #1
0
파일: sqglm.cpp 프로젝트: jiro-t/sqglm
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;
}
예제 #2
0
void SquirrelThread::initThread(HSQUIRRELVM parentVm)
{
    m_oldTop = -1;
    m_parentVm = parentVm;

    createThread();

    // create a local environment for the m_thread
    HSQOBJECT env;
    sq_resetobject(&env);

    sq_newtable(m_thread);

    // store the object in env
    if(sq_getstackobj(m_thread, -1, &env) < 0) 
    { return; }
    
    sq_addref(m_thread, &env); 
    sq_pop(m_thread, 1); // remove env from stack

    // set old roottable as delegate on env
    sq_pushobject(m_thread, env); // push env
    sq_pushroottable(m_thread);   // [env, root]
    sq_setdelegate(m_thread, -2); // env.set_delegate(root)
    sq_pop(m_thread, 1);          // pop env

    // set env as new roottable
    sq_pushobject(m_thread, env);
    sq_setroottable(m_thread);

    sq_release(m_thread, &env);
}
예제 #3
0
파일: sq_ffi.cpp 프로젝트: gdos/squilu-1
static inline void sq_create_delegate_table(HSQUIRRELVM vm, SQRegFunction *methods, HSQOBJECT *handle)
{
    sq_newtable(vm);
    sq_insert_reg_funcs(vm, methods);
    sq_resetobject(handle);
    sq_getstackobj(vm, -1, handle);
    sq_addref(vm, handle);
}
예제 #4
0
HSQOBJECT vm_to_object(HSQUIRRELVM vm)
{
  HSQOBJECT object;
  sq_resetobject(&object);
  object._unVal.pThread = vm;
  object._type = OT_THREAD;

  return object;
}
예제 #5
0
void CSquirrelVM::SetClassInstance(const char* szClassName, void * pInstance)
{
	sq_setinstanceup(m_pVM, 1, (SQUserPointer *) pInstance);
	sq_setreleasehook(m_pVM, 1, deleteClassInstance);

	HSQOBJECT instance;
	sq_resetobject(&instance);
	sq_getstackobj(m_pVM, 1, &instance);
	sq_addref(m_pVM, &instance);
	m_Instances.insert(std::pair<void*, HSQOBJECT>(pInstance, instance));
}
예제 #6
0
SQDbgServer::SQDbgServer(HSQUIRRELVM v)
{
	_ready = false;
	_nestedcalls = 0;
	_autoupdate = false;
	_v = v;
	_state = eDBG_Running;
	_accept = INVALID_SOCKET;
	_endpoint = INVALID_SOCKET;
	_maxrecursion = 10;
	sq_resetobject(&_debugroot);
}
예제 #7
0
HSQOBJECT create_thread(HSQUIRRELVM vm)
{
  HSQUIRRELVM new_vm = sq_newthread(vm, 64);
  if(new_vm == NULL)
    throw SquirrelError(vm, "Couldn't create new VM");

  HSQOBJECT vm_object;
  sq_resetobject(&vm_object);
  if(SQ_FAILED(sq_getstackobj(vm, -1, &vm_object)))
    throw SquirrelError(vm, "Couldn't get squirrel thread from stack");
  sq_addref(vm, &vm_object);

  sq_pop(vm, 1);

  return vm_object;
}
예제 #8
0
void CSquirrelVM::PushInstance(const char* szClassName, void * pInstance)
{
	// TODO:: remove instances when they are destoryed
	if (m_Instances.find(pInstance) != m_Instances.end())
	{
		sq_pushobject(m_pVM, m_Instances.find(pInstance)->second);
	}
	else
	{
		CreateConstructNativeClassInstance(m_pVM, szClassName);

		sq_setinstanceup(m_pVM, -1, (SQUserPointer *) pInstance);
		sq_setreleasehook(m_pVM, -1, deleteClassInstance);

		HSQOBJECT instance;
		sq_resetobject(&instance);
		sq_getstackobj(m_pVM, -1, &instance);
		sq_addref(m_pVM, &instance);
		m_Instances.insert(std::pair<void*, HSQOBJECT>(pInstance, instance));
	}
}
예제 #9
0
SQInteger Sq_RegisterMenu(HSQUIRRELVM v) {
  const SQChar *What;
  HSQOBJECT Handler;
  sq_resetobject(&Handler);
  sq_getstackobj(v, 2, &Handler);
  sq_getstring(v, 3, &What);
  sq_addref(v, &Handler);

  SquirrelHook *NewHook = (SquirrelHook*)malloc(sizeof(SquirrelHook));
  if(!NewHook) exit(0);

  // add new menu command
  strlcpy(NewHook->Name, What, sizeof(NewHook->Name));
  NewHook->Script = v;
  NewHook->Function = Handler;
  NewHook->Prev = NULL;
  NewHook->Next = AllMenuCommands;
  if(AllMenuCommands)
    AllMenuCommands->Prev = NewHook;
  AllMenuCommands = NewHook;
  return 0;
}
예제 #10
0
void SquirrelThread::createThread()
{
    //assert(!m_thread);

    m_thread = sq_newthread(m_parentVm, 1024);  // create m_thread and store it on the stack

    if (0 == m_thread) { 
        ASSERT_NOT_REACHED(); 
        return; 
    }
    
    // Create a HSQOBJECT to hold a reference to the m_thread
    sq_resetobject(&m_threadObj); // init the object

    // store m_thread created by sq_newthread into thread_obj
    if (sq_getstackobj(m_parentVm, -1, &m_threadObj) < 0) { 
        ASSERT_NOT_REACHED(); 
        return; 
    }

    sq_addref(m_parentVm, &m_threadObj); // add reference
    sq_pop(m_parentVm, 1); // remove the m_thread from the stack
}
예제 #11
0
static void release_visitor_cb(MyLibClang *self)
{
    sq_release(self->v, &self->visitor_cb);
    sq_resetobject(&self->visitor_cb);
}
예제 #12
0
void ScriptObject::reset(void)
{
	sq_release(mSqvm, &mObj);
	sq_resetobject(&mObj);
}
예제 #13
0
SquirrelObject::SquirrelObject(void)
{
	 sq_resetobject(&_o);
}