Ejemplo n.º 1
0
BOOL SquirrelObject::Next(SquirrelObject &key,SquirrelObject &val)
{
	if(SQ_SUCCEEDED(sq_next(m_Vm.GetVMPtr(),-2))) {
		key.AttachToStackObject(-2);
		val.AttachToStackObject(-1);
		sq_pop(m_Vm.GetVMPtr(),2);
		return TRUE;
	}
	return FALSE;
}
Ejemplo n.º 2
0
////////////////////////////////////////////////////////////////////////////////
// register a script plugin (script-bound function)
////////////////////////////////////////////////////////////////////////////////
SQInteger RegisterPlugin(HSQUIRRELVM v)
{
    // get squirrel object to register from stack
    SquirrelObject o;
    o.AttachToStackObject(2);

    // first verify that there is a member function to retrieve the plugin info
    if (!o.Exists("GetPluginInfo"))
        return sq_throwerror(v, "Not a script plugin!");

    // ask for its registration name
    SqPlus::SquirrelFunction<PluginInfo&> f(o, "GetPluginInfo");
    PluginInfo& info = f();
    wxString s = info.name;

    // look if a script plugin with the same name already exists
    ScriptPlugins::iterator it = s_ScriptPlugins.find(s);
    if (it != s_ScriptPlugins.end())
    {
        // already exists; release the old one
        s_ScriptPlugins.erase(it);
        Manager::Get()->GetLogManager()->Log(_("Script plugin unregistered: ") + s);
    }

    // finally, register this script plugin
    it = s_ScriptPlugins.insert(s_ScriptPlugins.end(), std::make_pair(s, o));
    Manager::Get()->GetLogManager()->Log(_("Script plugin registered: ") + s);

    Manager::Get()->GetScriptingManager()->RegisterScriptPlugin(s, CreateMenu(s));

    // this function returns nothing on the squirrel stack
    return 0;
}
Ejemplo n.º 3
0
SquirrelObject SquirrelObject::GetValue(const SQChar *key)/*const*/
{
	SquirrelObject ret;
	if(GetSlot(key)) {
		ret.AttachToStackObject(-1);
		sq_pop(m_Vm.GetVMPtr(),1);
	}
	sq_pop(m_Vm.GetVMPtr(),1);
	return ret;
}
Ejemplo n.º 4
0
SquirrelObject SquirrelObject::GetDelegate()
{
	SquirrelObject ret;
	if(_o._type == OT_TABLE || _o._type == OT_USERDATA)
	{
		sq_pushobject(m_Vm.GetVMPtr(),_o);
		sq_getdelegate(m_Vm.GetVMPtr(),-1);
		ret.AttachToStackObject(-1);
		sq_pop(m_Vm.GetVMPtr(),2);
	}
	return ret;
}
Ejemplo n.º 5
0
SquirrelObject SquirrelObject::Clone()
{
	SquirrelObject ret;
	if(GetType() == OT_TABLE || GetType() == OT_ARRAY)
	{
		sq_pushobject(m_Vm.GetVMPtr(),_o);
		sq_clone(m_Vm.GetVMPtr(),-1);
		ret.AttachToStackObject(-1);
		sq_pop(m_Vm.GetVMPtr(),2);
	}
	return ret;

}
Ejemplo n.º 6
0
SquirrelObject SquirrelObject::GetAttributes(const SQChar *key)
{
	SquirrelObject ret;
	int top = sq_gettop(m_Vm.GetVMPtr());
	sq_pushobject(m_Vm.GetVMPtr(),_o);
	if(key)
		sq_pushstring(m_Vm.GetVMPtr(),key,-1);
	else
		sq_pushnull(m_Vm.GetVMPtr());
	if(SQ_SUCCEEDED(sq_getattributes(m_Vm.GetVMPtr(),-2))) {
		ret.AttachToStackObject(-1);
	}
	sq_settop(m_Vm.GetVMPtr(),top);
	return ret;
}
Ejemplo n.º 7
0
BOOL CreateClass(HSQUIRRELVM v,SquirrelObject & newClass,SQUserPointer classType,const SQChar * name,const SQChar * baseName) {
  int n = 0;
  int oldtop = sq_gettop(v);
  sq_pushroottable(v);
  sq_pushstring(v,name,-1);
  if (baseName) {
    sq_pushstring(v,baseName,-1);
    if (SQ_FAILED(sq_get(v,-3))) { // Make sure the base exists if specified by baseName.
      sq_settop(v,oldtop);
      return FALSE;
    } // if
  } // if
  if (SQ_FAILED(sq_newclass(v,baseName ? 1 : 0))) { // Will inherit from base class on stack from sq_get() above.
    sq_settop(v,oldtop);
    return FALSE;
  } // if
  newClass.AttachToStackObject(-1);
  sq_settypetag(v,-1,classType);
  sq_createslot(v,-3);
  sq_pop(v,1);
  return TRUE;
} // CreateClass