/* * set preference value with given key * * @param preference key * @param preference value * @return EMO_NO_ERROR if succeeds */ SQInteger emoDatabaseSetPreference(HSQUIRRELVM v) { const SQChar* key; SQInteger nargs = sq_gettop(v); if (nargs >= 2 && sq_gettype(v, 2) != OT_NULL) { sq_tostring(v, 2); sq_getstring(v, -1, &key); sq_poptop(v); } else { sq_pushinteger(v, ERR_INVALID_PARAM); return 1; } const SQChar* value; if (nargs >= 3 && sq_gettype(v, 3) != OT_NULL) { sq_tostring(v, 3); sq_getstring(v, -1, &value); sq_poptop(v); } else { sq_pushinteger(v, ERR_INVALID_PARAM); return 1; } if (!engine->database->setPreference(key, value)) { sq_pushinteger(v, ERR_DATABASE); return 1; } sq_pushinteger(v, EMO_NO_ERROR); return 1; }
/* * open database with given name * if database is not found, creates new database with given name * file mode is one of FILE_MODE_PRIVATE, FILE_MODE_WORLD_READABLE * or FILE_MODE_WORLD_WRITABLE * * @param database name * @param file mode * @return EMO_NO_ERROR if succeeds */ SQInteger emoDatabaseOpenOrCreate(HSQUIRRELVM v) { const SQChar* name; SQInteger nargs = sq_gettop(v); if (nargs >= 2 && sq_gettype(v, 2) == OT_STRING) { sq_tostring(v, 2); sq_getstring(v, -1, &name); sq_poptop(v); } else { sq_pushinteger(v, ERR_INVALID_PARAM); return 1; } SQInteger mode = FILE_MODE_PRIVATE; if (nargs >= 3 && sq_gettype(v, 3) == OT_INTEGER) { sq_getinteger(v, 3, &mode); } if (!engine->database->openOrCreate(name, mode)) { sq_pushinteger(v, ERR_DATABASE_OPEN); return 1; } sq_pushinteger(v, EMO_NO_ERROR); return 1; }
/* * Runtime logging * * @param log level * @param log message */ SQInteger emoRuntimeLog(HSQUIRRELVM v) { SQInteger nargs = sq_gettop(v); SQInteger level; const SQChar *message; if (nargs < 3) return 0; if (sq_gettype(v, 2) == OT_INTEGER && sq_gettype(v, 3) == OT_STRING) { sq_getinteger(v, 2, &level); sq_tostring(v, 3); sq_getstring(v, -1, &message); sq_poptop(v); switch (level) { case LOG_INFO: LOGI((char*) message); break; case LOG_ERROR: LOGE((char*) message); break; case LOG_WARN: LOGW((char*) message); break; } } return 0; }
void ElementInterface::Bind(HSQUIRRELVM vm) { sq_pushroottable(vm); NamespaceHelper::switchTo(vm, "Rocket"); ElementStyleProxy::Bind(vm); //ElementList sqb::ClassDefinition<VectorInterface<ElementWrapperList>> cVec(vm, -1, _SC("ElementList")); cVec.ClassFunction(&VectorInterface<ElementWrapperList>::Contains, _SC("Contains")); cVec.ClassFunction(&VectorInterface<ElementWrapperList>::SetItem, _SC("_set")); cVec.NativeClassFunction(&VectorInterface<ElementWrapperList>::GetItem, _SC("_get"), sqb::FunctionOptions().ParamCheckCount(-2).TypeMask(_SC("xi"))); cVec.ClassFunction(&VectorInterface<ElementWrapperList>::PushBack, _SC("append")); cVec.ClassFunction(&VectorInterface<ElementWrapperList>::PushBack, _SC("push")); cVec.ClassFunction(&VectorInterface<ElementWrapperList>::Size, _SC("len")); cVec.ClassFunction(&VectorInterface<ElementWrapperList>::DelItem, _SC("remove")); sq_poptop(vm); ElementWrapper::Bind(vm); ElementDocumentWrapper::Bind(vm); ElementTextWrapper::Bind(vm); //hmm can't access ElementTextDefault, ElementImage and ElementHandle }
static void Register(HSQUIRRELVM v) { PropEntry props[] = { PROP_ENTRY (orientation), PROP_ENTRY_R(portrait), PROP_ENTRY_R(landscape), PROP_ENTRY_R(left), PROP_ENTRY_R(top), PROP_ENTRY_R(width), PROP_ENTRY_R(height), PROP_ENTRY (scale), PROP_ENTRY_R(scaledWidth), PROP_ENTRY_R(scaledHeight), PROP_ENTRY_R(renderDevice), PROP_ENTRY_R(inputDevice), NULL }; FuncEntry funcs[] = { FUNC_ENTRY_H(channel, "(): EventChannel"), NULL }; bind(v, props, funcs); addStaticTable(v, "ORIENT"); newSlot(v, -1, "PORTRAIT", (int)type::ORIENT_PORTRAIT); newSlot(v, -1, "PORTRAIT_FLIP", (int)type::ORIENT_PORTRAIT_FLIP); newSlot(v, -1, "LANDSCAPE", (int)type::ORIENT_LANDSCAPE); newSlot(v, -1, "LANDSCAPE_FLIP", (int)type::ORIENT_LANDSCAPE_FLIP); sq_poptop(v); }
/* * compile script from path * * @param script file name */ SQInteger emoRuntimeCompile(HSQUIRRELVM v) { if (sq_gettype(v, 2) == OT_STRING) { const SQChar *fname; sq_tostring(v, 2); sq_getstring(v, -1, &fname); sq_poptop(v); // check if the file type exists if (sq_gettype(v, 3) == OT_INTEGER) { SQInteger fileType = TYPE_ASSET; sq_getinteger(v, 3, &fileType); if (fileType == TYPE_ASSET) { // load script from resource loadScriptFromAsset((char*) fname); } else if (fileType == TYPE_DOCUMENT) { // load script from user document directory loadScriptFromUserDocument(fname); } else { // load script from path loadScript(fname); } } else { // load script from path loadScript(fname); } } return 0; }
NITRENDER_API SQRESULT NitLibRender(HSQUIRRELVM v) { NB_RenderSpec::Register(v); NB_RenderContext::Register(v); NB_RenderDevice::Register(v); NB_RenderView::Register(v); NB_RenderService::Register(v); // TODO: Do not expose GLES* NB_GLESTexture::Register(v); NB_GLESTextureManager::Register(v); //////////////////////////////////// sq_pushroottable(v); if (g_Service) { NitBind::newSlot(v, -1, "render", g_Render); } sq_poptop(v); return SQ_OK; }
SQUserPointer ScriptObject::getInstanceUp(SQUserPointer tag) const { SQUserPointer up = 0; sq_pushobject(mSqvm, mObj); sq_getinstanceup(mSqvm, -1, (SQUserPointer*)&up, tag); sq_poptop(mSqvm); return up; }
ScriptObject ScriptObject::getValue(const char* key) const { ScriptObject ret(mSqvm); if(_getSlot(key)) MCD_VERIFY(ret.getFromStack(-1)); sq_poptop(mSqvm); return ret; }
bool ScriptObject::setInstanceUp(SQUserPointer up) { MCD_ASSERT(sq_isinstance(mObj)); sq_pushobject(mSqvm, mObj); sq_setinstanceup(mSqvm, -1, up); sq_poptop(mSqvm); return true; }
//Binding function void EventInterface::Bind(HSQUIRRELVM vm) { sq_pushroottable(vm); NamespaceHelper::switchTo(vm, "Rocket"); EventWrapper::Bind(vm); sq_poptop(vm); return; }
template <> inline const char *GetParam(ForceType<const char *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { sq_tostring(vm, index); const SQChar *tmp; sq_getstring(vm, -1, &tmp); char *tmp_str = strdup(SQ2OTTD(tmp)); sq_poptop(vm); *ptr->Append() = (void *)tmp_str; str_validate(tmp_str, tmp_str + strlen(tmp_str)); return tmp_str; }
static void Register(HSQUIRRELVM v) { PropEntry props[] = { PROP_ENTRY_R(numWorldMatrices), PROP_ENTRY_R(numTextureUnits), PROP_ENTRY_R(numVertexBlendMatrices), PROP_ENTRY_R(numVertexTextureUnits), PROP_ENTRY_R(maxTextureSize), PROP_ENTRY_R(maxViewportWidth), PROP_ENTRY_R(maxViewportHeight), PROP_ENTRY_R(numDepthBufferBits), PROP_ENTRY_R(numStencilBufferBits), PROP_ENTRY_R(numVertexShaderFloatConsts), PROP_ENTRY_R(numVertexShaderIntConsts), PROP_ENTRY_R(numVertexShaderBoolConsts), PROP_ENTRY_R(numGeometryShaderFloatConsts), PROP_ENTRY_R(numGeometryShaderIntConsts), PROP_ENTRY_R(numGeometryShaderBoolConsts), PROP_ENTRY_R(numPixelShaderFloatConsts), PROP_ENTRY_R(numPixelShaderIntConsts), PROP_ENTRY_R(numPixelShaderBoolConsts), PROP_ENTRY_R(numMultiRenderTargets), NULL }; FuncEntry funcs[] = { FUNC_ENTRY_H(isCapable, "(spec: int): bool"), FUNC_ENTRY_H(report, "(ch: LogChannel = null)"), NULL }; bind(v, props, funcs); vector<std::pair<String, uint32> >::type specs; RenderSpec::allSpecs(specs); for (uint i=0; i<specs.size(); ++i) { const String& name = specs[i].first; size_t ppos = name.find('.'); if (ppos != name.npos) { addStaticTable(v, name.substr(0, ppos).c_str(), false, false); newSlot(v, -1, name.substr(ppos+1), specs[i].second); sq_poptop(v); } else { addStatic(v, name.c_str(), specs[i].second); } } }
void lib_finder::UnregisterScripting() { Manager::Get()->GetScriptingManager(); HSQUIRRELVM v = SquirrelVM::GetVMPtr(); if ( v ) { sq_pushroottable(v); sq_pushstring(v,"LibFinder",-1); sq_deleteslot(v,-2,false); sq_poptop(v); } }
SQRESULT NitLibCom(HSQUIRRELVM v) { NitLibCom::Register(v); NitBindComTypeLib::Register(v); NitBindCom* com = new NitBindCom(v); sq_pushroottable(v); sq_pushstring(v, "com", -1); NitBind::push(v, com); sq_newslot(v, -3, true); sq_poptop(v); // Prevent deletion from registry sq_pushregistrytable(v); sq_pushuserpointer(v, com); NitBind::push(v, com); sq_newslot(v, -3, true); sq_poptop(v); return SQ_OK; }
void EnvVars::OnRelease(bool /*appShutDown*/) { // Unregister scripting Manager::Get()->GetScriptingManager(); // make sure the VM is initialised HSQUIRRELVM v = SquirrelVM::GetVMPtr(); if (v) { // TODO (Morten#5#): Is that the correct way of un-registering? (Seems so weird...) sq_pushroottable(v); sq_pushstring(v, "EnvvarDiscard", -1); sq_deleteslot(v, -2, false); sq_poptop(v); sq_pushroottable(v); sq_pushstring(v, "EnvvarApply", -1); sq_deleteslot(v, -2, false); sq_poptop(v); sq_pushroottable(v); sq_pushstring(v, "EnvvarSetDiscard", -1); sq_deleteslot(v, -2, false); sq_poptop(v); sq_pushroottable(v); sq_pushstring(v, "EnvvarSetApply", -1); sq_deleteslot(v, -2, false); sq_poptop(v); sq_pushroottable(v); sq_pushstring(v, "EnvvarSetExists", -1); sq_deleteslot(v, -2, false); sq_poptop(v); sq_pushroottable(v); sq_pushstring(v, "EnvVarGetEnvvarsBySetPath", -1); sq_deleteslot(v, -2, false); sq_poptop(v); sq_pushroottable(v); sq_pushstring(v, "EnvvarGetActiveSetName", -1); sq_deleteslot(v, -2, false); sq_poptop(v); sq_pushroottable(v); sq_pushstring(v, "EnvvarGetEnvvarSetNames", -1); sq_deleteslot(v, -2, false); sq_poptop(v); } }// OnRelease
/* * Import function called from squirrel script */ SQInteger emoImportScript(HSQUIRRELVM v) { SQInteger nargs = sq_gettop(v); for (SQInteger n = 1; n <= nargs; n++) { if (sq_gettype(v, n) == OT_STRING) { const SQChar *fname; sq_tostring(v, n); sq_getstring(v, -1, &fname); sq_poptop(v); loadScriptFromAsset((char*) fname); } } return 0; }
void wxWidgetsResFactory::OnRelease() { // TODO: Call OnRelease for item factories // Unregistering wizard function Manager::Get()->GetScriptingManager(); HSQUIRRELVM v = SquirrelVM::GetVMPtr(); if ( v ) { sq_pushroottable(v); sq_pushstring(v,"WxsAddWxExtensions",-1); sq_deleteslot(v,-2,false); sq_poptop(v); } }
/* * compile script from given string * * @param squirrel program as string */ SQInteger emoRuntimeCompileBuffer(HSQUIRRELVM v) { const SQChar* script; SQInteger nargs = sq_gettop(v); if (nargs >= 2 && sq_gettype(v, 2) == OT_STRING) { sq_tostring(v, 2); sq_getstring(v, -1, &script); sq_poptop(v); } else { sq_pushinteger(v, ERR_INVALID_PARAM); return 1; } sq_pushinteger(v, sqCompileBuffer(v, script, EMO_RUNTIME_CLASS)); return 1; }
TextureManager::TextureManager() { HSQUIRRELVM vm = engine::script_engine->vm; sq_pushroottable(vm); // 1 sq_pushstring(vm, "Resources", -1); // 2 CSQ(sq_get(vm, -2)); // 2 sq_pushstring(vm, "TextureInfo", -1); // 3 sq_newtable(vm); // 4 CSQ(sq_newslot(vm, -3, SQFalse)); // 2 sq_poptop(vm); // 1 #define ADD_CONSTANT(name) \ sq_pushstring(vm, PREFIX #name, -1); \ sq_pushinteger(vm, static_cast<SQInteger>(ENUM_PREFIX name)); \ CSQ(sq_newslot(vm, -3, SQFalse)) #define PREFIX "TEXFILTER_" #define ENUM_PREFIX Texture::FilterMode:: ADD_CONSTANT(NEAREST); ADD_CONSTANT(LINEAR); ADD_CONSTANT(MIPMAP_LINEAR); #undef PREFIX #undef ENUM_PREFIX #define PREFIX "TEXREPEAT_" #define ENUM_PREFIX Texture::RepeatMode:: ADD_CONSTANT(CLAMP); ADD_CONSTANT(WRAP); #undef PREFIX #undef ENUM_PREFIX #undef ADD_CONSTANT sq_poptop(vm); // 0 }
void GlobalUtility::Restore() { Module::instance().getScriptInterface().PushDocumentTable(mVM, m_pDoc); if (mSelfSet) { deleteSlot("self"); mSelfSet = false; } if (mEvtSet) { deleteSlot("event"); mEvtSet = false; } sq_poptop(mVM); }
/* * returns preference value with given key * * @param preference key * @return preference value */ SQInteger emoDatabaseGetPreference(HSQUIRRELVM v) { const SQChar* key; SQInteger nargs = sq_gettop(v); if (nargs >= 2 && sq_gettype(v, 2) == OT_STRING) { sq_tostring(v, 2); sq_getstring(v, -1, &key); sq_poptop(v); } else { return 0; } std::string str = engine->database->getPreference(key); const char* cstr = str.c_str(); sq_pushstring(v, cstr, -1); return 1; }
/*fa MTR_ScriptsRegisterVariable_s yes */ MTR_DCLSPC bool MTR_CALL MTR_ScriptsRegisterVariable_s(const char *name, const char *value) { if ((name != NULL) && (strcmp(name, "") != 0)) { sq_pushroottable(mtrVm); sq_pushstring(mtrVm, name, -1); sq_pushstring(mtrVm, value, -1); sq_rawset(mtrVm, -3); sq_poptop(mtrVm); MTR_LogWrite_s("Script const added:", 3, MTR_LMT_INFO, name); return true; } else { MTR_LogWrite("Script const not added. Incorrect const name:", 3, MTR_LMT_ERROR); } return false; }
static SQRESULT sq_mysql_result_next_row(HSQUIRRELVM v){ SQ_FUNC_VARS_NO_TOP(v); GET_mysql_result_INSTANCE(); sq_pushstring(v, _curr_row_key, -1); sq_push(v, -1); //make a copy if(sq_get(v, 1) == SQ_OK){ SQ_GET_INTEGER(v, -1, curr_row); if(++curr_row < dlmysql_num_rows(self)){ sq_poptop(v); sq_pushinteger(v, curr_row); sq_set(v, 1); sq_pushbool(v, SQTrue); return 1; } } sq_pushbool(v, SQFalse); return 1; }
/* * returns database path with given name * * @param database name * @param database path */ SQInteger emoDatabaseGetPath(HSQUIRRELVM v) { const SQChar* name; SQInteger nargs = sq_gettop(v); if (nargs >= 2 && sq_gettype(v, 2) == OT_STRING) { sq_tostring(v, 2); sq_getstring(v, -1, &name); sq_poptop(v); } else { return 0; } std::string path = engine->database->getPath(name); const char* cpath = path.c_str(); sq_pushstring(v, cpath, -1); return 1; }
/* * Shows Android toast message */ SQInteger emoRuntimeAndroidToast(HSQUIRRELVM v) { SQInteger nargs = sq_gettop(v); const SQChar* text; if (nargs >= 2 && sq_gettype(v, 2) == OT_STRING) { sq_tostring(v, 2); sq_getstring(v, -1, &text); sq_poptop(v); } SQInteger duration = ANDROID_TOAST_SHORT; if (nargs <= 3 && sq_gettype(v, 3) == OT_INTEGER) { sq_getinteger(v, 3, &duration); } engine->javaGlue->callStringInt_Void("toast", text, duration); return 0; }
static SQInteger sq_lib_bind_func(HSQUIRRELVM v) { void **modbuf; void *mod; void *sym; const SQChar *symname; const char *rettype; sq_getuserdata(v, 1, (void**)&modbuf, NULL); mod = *modbuf; sq_getstring(v, 2, &rettype); sq_getstring(v, 3, &symname); sym = GET_SYM(mod, symname); if (!sym) return sq_throwerror(v, "Cannot find symbol"); int nparam = sq_getsize(v, 4); int size = sizeof(FFIFunc) + sizeof(ffi_type*) * nparam; FFIFunc *ffibuf = (FFIFunc*)sq_newuserdata(v, size); sq_push_delegate_table(v, FFI_LIB_FUNC_TAG); sq_setdelegate(v, -2); // printf("Allocated %d bytes at %p\n", size, ffibuf); ffibuf->func = sym; ffibuf->rettype = *rettype; int i; for (i = 0; i < nparam; i++) { sq_pushinteger(v, i); sq_get(v, 4); ffibuf->params[i] = get_ffi_type(v, -1); if (!ffibuf->params[i]) return SQ_ERROR; sq_poptop(v); } int res = ffi_prep_cif(&ffibuf->cif, FFI_DEFAULT_ABI, nparam, char2ffi_type(*rettype), ffibuf->params); if (res != FFI_OK) return sq_throwerror(v, "Error in ffi_prep_cif"); return 1; }
/* * Runtime echo * * @param message * @return given message */ SQInteger emoRuntimeEcho(HSQUIRRELVM v) { const SQChar *str; SQInteger nargs = sq_gettop(v); for (SQInteger n = 1; n <= nargs; n++) { if (sq_gettype(v, n) == OT_STRING) { sq_tostring(v, n); sq_getstring(v, -1, &str); sq_poptop(v); } else { str = NULL; } } if (str != NULL) { sq_pushstring(v, str, -1); } return 1; }
/* * delete preference with given key * * @param preference key * @return EMO_NO_ERROR if succeeds */ SQInteger emoDatabaseDeletePreference(HSQUIRRELVM v) { const SQChar* key; SQInteger nargs = sq_gettop(v); if (nargs >= 2 && sq_gettype(v, 2) == OT_STRING) { sq_tostring(v, 2); sq_getstring(v, -1, &key); sq_poptop(v); } else { sq_pushinteger(v, ERR_INVALID_PARAM); return 1; } if (!engine->database->deletePreference(key)) { sq_pushinteger(v, ERR_DATABASE); return 1; } sq_pushinteger(v, EMO_NO_ERROR); return 1; }
void GlobalUtility::Set() { Module::instance().getScriptInterface().PushDocumentTable(mVM, m_pDoc); SQRESULT sqr; if (m_pSelf) { ElementWrapper wrapper; wrapper.setElement(m_pSelf); //Add the global slot self sq_pushstring(mVM, "self", -1); sqr = sqb::Push<ElementWrapper>(mVM, wrapper); ROCKETSQUIRREL_ASSERT(SQ_SUCCEEDED(sqr)); sqr = sq_newslot(mVM, -3, false); ROCKETSQUIRREL_ASSERT(SQ_SUCCEEDED(sqr)); mSelfSet = true; } if (m_pEvt) { EventWrapper wrapper(m_pEvt); //Add the global slot event sq_pushstring(mVM, "event", -1); sqr = sqb::Push<EventWrapper>(mVM, wrapper); ROCKETSQUIRREL_ASSERT(SQ_SUCCEEDED(sqr)); sqr = sq_newslot(mVM, -3, false); ROCKETSQUIRREL_ASSERT(SQ_SUCCEEDED(sqr)); mEvtSet = true; } sq_poptop(mVM); }