本文整理汇总了C++中SquirrelObject类的典型用法代码示例。如果您正苦于以下问题:C++ SquirrelObject类的具体用法?C++ SquirrelObject怎么用?C++ SquirrelObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SquirrelObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RegisterPlugin
////////////////////////////////////////////////////////////////////////////////
// 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;
}
示例2: while
SquirrelObject RegularExpression::findAll(const std::string& str)
{
try {
size_t pos = 0;
SquirrelObject res = SquirrelVM::CreateArray(0);
while (pos <= str.length())
{
if ( pcre_->search(str, pos))
{
pos = pcre_->get_match_end()+1;
int count = matchesCount();
SquirrelObject mat = SquirrelVM::CreateArray(count);
for ( int i = 0; i < count; i++ ) {
mat.SetValue(i, pcre_->get_match(i).c_str());
}
res.ArrayAppend(mat);
}
else {
break;
}
}
return res;
} catch( Pcre::exception ex ) {
LOG(ERROR) << ex.what();
return SquirrelObject();
}
}
示例3: Next
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;
}
示例4: GetValue
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;
}
示例5: getInstanceVarInfo
static int getInstanceVarInfo(StackHandler & sa,VarRefPtr & vr,SQUserPointer & data) {
HSQOBJECT ho = sa.GetObjectHandle(1);
SquirrelObject instance(ho);
const SQChar * el = sa.GetString(2);
ScriptStringVar256 varNameTag;
getVarNameTag(varNameTag,sizeof(varNameTag),el);
SQUserPointer ivrData=0;
if (!instance.RawGetUserData(varNameTag,&ivrData)) {
return sa.ThrowError(_SC("getInstanceVarInfo: Could not retrieve UserData")); // Results in variable not being found error.
}
vr = (VarRefPtr)ivrData;
char * up;
if (!(vr->m_access & (VAR_ACCESS_STATIC|VAR_ACCESS_CONSTANT))) {
SQUserPointer typetag;
instance.GetTypeTag(&typetag);
#if defined(SQ_USE_CLASS_INHERITANCE)
if (typetag != vr->instanceType) {
SquirrelObject typeTable = instance.GetValue(SQ_CLASS_OBJECT_TABLE_NAME);
up = (char *)typeTable.GetUserPointer(INT((size_t)vr->instanceType)); // <TODO> 64-bit compatible version.
if (!up) {
throw SquirrelError(_SC("Invalid Instance Type"));
}
} else {
up = (char *)instance.GetInstanceUP(0);
} // if
#elif defined(SQ_USE_CLASS_INHERITANCE_SIMPLE)
ClassTypeBase *ctb = (ClassTypeBase*)vr->instanceType;
up = (char *)instance.GetInstanceUP(0);
// Walk base classes until type tag match, adjust for inheritence offset
while(ctb && typetag!=ctb) {
up = (char*)up - ctb->m_offset;
ctb = ctb->m_pbase;
}
if (!ctb) {
throw SquirrelError(_SC("Invalid Instance Type"));
}
#else
up = (char *)instance.GetInstanceUP(0);
#endif
#ifdef SQPLUS_SMARTPOINTER_OPT
#define SQPLUS_SMARTPOINTER_INSTANCE_VARINFO
#include "SqPlusSmartPointer.h"
#endif
up += (size_t)vr->offsetOrAddrOrConst; // Offset
} else {
up = (char *)vr->offsetOrAddrOrConst; // Address
} // if
data = up;
return SQ_OK;
} // getInstanceVarInfo
示例6: GetDelegate
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;
}
示例7: Clone
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;
}
示例8: catch
/*
RegularExpression::RegularExpression(const RegularExpression& r)
{
}
*/
SquirrelObject RegularExpression::split(const std::string& piece)
{
try {
std::vector<std::string> res = pcre_->split(piece);
SquirrelObject obj = SquirrelVM::CreateArray(res.size());
for( int i = 0; i < res.size(); i++ ) {
obj.SetValue(i, res[i].c_str());
}
return obj;
} catch( Pcre::exception ex ) {
LOG(ERROR) << ex.what();
return SquirrelObject();
}
}
示例9: GetAttributes
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;
}
示例10: SetDelegate
BOOL SquirrelObject::SetDelegate(SquirrelObject &obj)
{
if(obj.GetType() == OT_TABLE ||
obj.GetType() == OT_NULL) {
switch(_o._type) {
case OT_USERDATA:
case OT_TABLE:
sq_pushobject(m_Vm.GetVMPtr(),_o);
sq_pushobject(m_Vm.GetVMPtr(),obj._o);
if(SQ_SUCCEEDED(sq_setdelegate(m_Vm.GetVMPtr(),-2)))
return TRUE;
break;
}
}
return FALSE;
}
示例11: SquirrelObject
SquirrelObject RegularExpression::getSubStrings()
{
try {
std::vector<std::string>* substrings = pcre_->get_sub_strings();
if ( !substrings ) {
return SquirrelObject();
}
SquirrelObject res = SquirrelVM::CreateArray(substrings->size());
for ( int i = 0; i < substrings->size(); i++ ) {
res.SetValue(i, (*substrings)[i].c_str());
}
return res;
} catch( Pcre::exception ex ) {
LOG(ERROR) << ex.what();
return SquirrelObject();
}
}
示例12: EnterCriticalSection
void UIManager::Draw(HWND hWnd, HDC hdc)
{
EnterCriticalSection(&m_DrawCrit);
int before, after;
unsigned int i, cnt = 0;
std::vector<LyricLine> lyric = LyricManagerInstance->GetLyric();
after = before = m_Setting->GetnLine() / 2 - lyric.size() / 2;
if(after < 0)
after = 0;
if(before < 0)
before = 0;
std::vector<LyricLine> lyricbefore = LyricManagerInstance->GetLyricBefore(before);
std::vector<LyricLine> lyricafter = LyricManagerInstance->GetLyricAfter(after + lyric.size() - 1 - (1 - m_Setting->GetnLine() % 2));
//현재 가사가 1줄 이상인 경우에는 두번째 줄부터
if(!lyric.size())
return;
SquirrelVM::SetVMSys(m_vmSys);
SquirrelObject lyrics = SquirrelVM::CreateArray(0);
for(i = 0; i < before - lyricbefore.size(); i ++)
lyrics.ArrayAppend((std::wstring(1, (wchar_t)2) + TEXT(" ")).c_str());
if(lyric.size() < m_Setting->GetnLine())
{
for(i = 0; i < lyricbefore.size(); i ++)
{
std::wstring nowlrcw = std::wstring(1, (wchar_t)2) + pfc::stringcvt::string_wide_from_utf8_fast(lyricbefore[i].lyric.c_str()).get_ptr();
lyrics.ArrayAppend(nowlrcw.c_str());
}
}
for(i = 0; i < lyric.size(); i ++)
{
std::wstring nowlrcw = std::wstring(1, (wchar_t)1) + pfc::stringcvt::string_wide_from_utf8_fast(lyric[i].lyric.c_str()).get_ptr();
lyrics.ArrayAppend(nowlrcw.c_str());
}
for(i = max(lyric.size() - 1, 0); i < lyricafter.size(); i ++)
{
std::wstring nowlrcw = std::wstring(1, (wchar_t)2) + pfc::stringcvt::string_wide_from_utf8_fast(lyricafter[i].lyric.c_str()).get_ptr();
lyrics.ArrayAppend(nowlrcw.c_str());
}
UICanvas canvas(hWnd, hdc);
SqPlus::SquirrelFunction<void>(m_RootTable, TEXT("Draw"))(&canvas, lyrics);
LeaveCriticalSection(&m_DrawCrit);
}
示例13: getInstanceVarInfo
static int getInstanceVarInfo(StackHandler & sa,VarRefPtr & vr,SQUserPointer & data) {
HSQOBJECT ho = sa.GetObjectHandle(1);
SquirrelObject instance(ho);
#ifdef _DEBUG
SQObjectType type = (SQObjectType)sa.GetType(2);
#endif
const SQChar * el = sa.GetString(2);
ScriptStringVar256 varNameTag;
getVarNameTag(varNameTag,sizeof(varNameTag),el);
SQUserPointer ivrData=0;
if (!instance.RawGetUserData(varNameTag,&ivrData)) {
// throw SquirrelError("getInstanceVarInfo: Could not retrieve UserData");
return sa.ThrowError(_T("getInstanceVarInfo: Could not retrieve UserData")); // Results in variable not being found error.
} // if
vr = (VarRefPtr)ivrData;
unsigned char * up;
if (!(vr->access & (VAR_ACCESS_STATIC|VAR_ACCESS_CONSTANT))) {
#ifdef SQ_USE_CLASS_INHERITANCE
SQUserPointer typetag; instance.GetTypeTag(&typetag);
if (typetag != vr->instanceType) {
SquirrelObject typeTable = instance.GetValue(SQ_CLASS_OBJECT_TABLE_NAME);
up = (unsigned char *)typeTable.GetUserPointer(INT((size_t)vr->instanceType)); // <TODO> 64-bit compatible version.
if (!up) {
#if defined( MONASQ )
return sa.ThrowError(_T("Invalid Instance Type"));
#else
throw SquirrelError(_T("Invalid Instance Type"));
#endif
} // if
} else {
up = (unsigned char *)instance.GetInstanceUP(0);
} // if
#else
up = (unsigned char *)instance.GetInstanceUP(0);
#endif
up += (size_t)vr->offsetOrAddrOrConst; // Offset
} else {
up = (unsigned char *)vr->offsetOrAddrOrConst; // Address
} // if
data = up;
return SQ_OK;
} // getInstanceVarInfo
示例14: GetAppVersion
SquirrelObject GetAppVersion() {
SquirrelObject res = SquirrelVM::CreateTable();
std::string ver = _APP_VER;
std::vector<std::string> tokens;
IuStringUtils::Split(ver,".", tokens, 3);
if ( tokens.size() >=3 ) {
res.SetValue("Major", (SQInteger)IuCoreUtils::stringToint64_t(tokens[0]));
res.SetValue("Minor", (SQInteger)IuCoreUtils::stringToint64_t(tokens[1]));
res.SetValue("Release", (SQInteger)IuCoreUtils::stringToint64_t(tokens[2]));
res.SetValue("Build", (SQInteger)IuCoreUtils::stringToint64_t(BUILD));
bool isGui =
#ifndef IU_CLI
true;
#else
false;
#endif
res.SetValue("Gui",isGui);
}
return res;
}
示例15: CreateClass
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