本文整理汇总了C++中HSQUIRRELVM::GetAt方法的典型用法代码示例。如果您正苦于以下问题:C++ HSQUIRRELVM::GetAt方法的具体用法?C++ HSQUIRRELVM::GetAt怎么用?C++ HSQUIRRELVM::GetAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HSQUIRRELVM
的用法示例。
在下文中一共展示了HSQUIRRELVM::GetAt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: at
SQRESULT at(HSQUIRRELVM vm) {
SQObjectPtr self = vm->GetAt(vm->_top-2);
if (type(self) == OT_STRING) {
SQString *selfString = _string(self);
SQInteger index = selfString->_len;
sq_getinteger(vm, -1, &index);
auto begin = selfString->_val;
auto end = begin+selfString->_len;
try {
SQChar *from = NULL;
if (index >= 0) {
from = begin; utf8::advance(from, index, end);
}
else {
from = end;
for (auto i = index; i < 0; ++i) {
utf8::prior(from, begin);
}
}
auto to = from; utf8::advance(to, 1, end);
SQInteger resultLen = to-from;
assert((resultLen >= 0) && "Length of the resulting string should not be negative");
if (resultLen < 0) {
sq_pushnull(vm);
return 1;
}
SQChar *resultSequence = vm->_sharedstate->GetScratchPad(resultLen+1);
memset(resultSequence, 0, (resultLen+1)*sizeof(SQChar));
memcpy(resultSequence, from, resultLen*sizeof(SQChar));
SQString *result = SQString::Create(vm->_sharedstate, resultSequence);
vm->Push(result);
} catch (...) {
sq_pushnull(vm);
}
}
else {
vm->Raise_Error("string::at - Invalid receiver of type %s", GetTypeName(self));
return SQ_ERROR;
}
return 1;
}
示例2: map_single
static SQRESULT map_single(HSQUIRRELVM vm) {
SQObjectPtr closure = vm->GetAt(vm->_top-1);
if ((sq_type(closure) != OT_CLOSURE) && (sq_type(closure) != OT_NATIVECLOSURE)) {
vm->Raise_ParamTypeError(1, OT_CLOSURE | OT_NATIVECLOSURE, sq_type(closure));
return 0;
}
SQObjectPtr result;
result.Null();
sq_push(vm, -2); // push self as implicit `this`
sq_push(vm, -3); // push self as parameter
vm->Call(closure, 2, vm->_top-2, result, SQTrue);
sq_pop(vm, 1); // pop self x2
vm->Push(result);
return 1;
}