bool TVPAcceptSaveAsTLG(void* formatdata, const ttstr & type, class iTJSDispatch2** dic ) { bool result = false; if( type.StartsWith(TJS_W("tlg")) ) result = true; else if( type == TJS_W(".tlg") ) result = true; else if( type == TJS_W(".tlg5") ) result = true; else if( type == TJS_W(".tlg6") ) result = true; if( result && dic ) { // mode : select text : opaque, alpha, add, sub, mul, dodge, darken, lighten, screen, addalpha // psnormal, psadd, pssub, psmul, psscreen, psoverlay, pshlight, psslight, psdodge // psdodge5, psburn, pslighten, psdarken, psdiff, psdiff5, psexcl, opaque // offs_x : integer // offs_y : integer // offs_unit : select text : pixel tTJSVariant result; TVPExecuteExpression( TJS_W("(const)%[") TJS_W("\"mode\"=>(const)%[\"type\"=>\"select text\",\"items\"=>") TJS_W("(const)[\"opaque\", \"alpha\", \"add\", \"sub\", \"mul\", \"dodge\", \"darken\", \"lighten\", \"screen\", \"addalpha\",") TJS_W("\"psnormal\", \"psadd\", \"pssub\", \"psmul\", \"psscreen\", \"psoverlay\", \"pshlight\", \"psslight\", \"psdodge\",") TJS_W("\"psdodge5\", \"psburn\", \"pslighten\", \"psdarken\", \"psdiff\", \"psdiff5\", \"psexcl\", \"opaque\"],") TJS_W("\"desc\"=>\"blending mode\",\"default\"=>\"alpha\"],") TJS_W("\"offs_x\"=>(const)%[\"type\"=>\"integer\",\"desc\"=>\"offset x\",\"default\"=>0],") TJS_W("\"offs_y\"=>(const)%[\"type\"=>\"integer\",\"desc\"=>\"offset y\",\"default\"=>0],") TJS_W("\"offs_unit\"=>(const)%[\"type\"=>\"select text\",\"items\"=>(const)[\"pixel\"],\"desc\"=>\"offset unit\",\"default\"=>\"pixel\"]") TJS_W("]"), NULL, &result ); if( result.Type() == tvtObject ) { *dic = result.AsObject(); } } return result; }
extern "C" __declspec(dllexport) HRESULT __stdcall V2Link(iTVPFunctionExporter *exporter) { // スタブの初期化(必ず記述する) TVPInitImportStub(exporter); // 初期化 prevTime = TVPGetTickCount(); TVPAddContinuousEventHook(&limit); { // TJS のグローバルオブジェクトを取得する iTJSDispatch2 * global = TVPGetScriptDispatch(); // Layer クラスオブジェクトを取得 tTJSVariant varScripts; TVPExecuteExpression(TJS_W("System"), &varScripts); iTJSDispatch2 *dispatch = varScripts.AsObjectNoAddRef(); if (dispatch) { tTJSDispatch *method = new tFpsLimitProp(); tTJSVariant var(method); dispatch->PropSet(TJS_MEMBERENSURE, FPSLIMITNAME, NULL, &var, dispatch); method->Release(); } global->Release(); } GlobalRefCountAtInit = TVPPluginGlobalRefCount; return S_OK; }
ObjectCache(DispatchT obj, NameT name) : _obj(obj), _cache(0), _name(name) { tTJSVariant layer; TVPExecuteExpression(TJS_W("Layer"), &layer); tTJSVariant var; if (TJS_SUCCEEDED(layer.AsObjectNoAddRef()->PropGet(TJS_IGNOREPROP, name, NULL, &var, layer.AsObjectNoAddRef()))) _cache = var; else _Exception(TJS_W("FAILED: get property object :")); }
static tTVInteger LayerPropGet(iTJSDispatch2 *lay, ttstr &prop, tTVInteger defval = 0) { if (!LayerClass) { tTJSVariant var; TVPExecuteExpression(TJS_W("Layer"), &var); LayerClass = var.AsObjectNoAddRef(); } tTJSVariant val; return (TJS_FAILED(LayerClass->PropGet(0, prop.c_str(), prop.GetHint(), &val, lay))) ? defval : val.AsInteger(); }
/** * 吉里吉里クラスから Javascript クラスを生成 * @param args 引数 * @return 結果 */ void TJSInstance::createTJSClass(const FunctionCallbackInfo<Value>& args) { Isolate *isolate = args.GetIsolate(); HandleScope handle_scope(isolate); if (args.Length() < 1) { args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "invalid param"))); return; } // TJSクラス情報取得 String::Value tjsClassName(args[0]); tTJSVariant tjsClassObj; TVPExecuteExpression(*tjsClassName, &tjsClassObj); if (tjsClassObj.Type() != tvtObject || TJS_FAILED(tjsClassObj.AsObjectClosureNoAddRef().IsInstanceOf(0,NULL,NULL,L"Class",NULL))) { args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "invalid param"))); return; } // クラステンプレートを生成 Local<FunctionTemplate> classTemplate = FunctionTemplate::New(isolate, tjsConstructor, TJSObject::toJSObject(isolate, tjsClassObj)); classTemplate->SetClassName(args[0]->ToString()); // 表示名 // メンバ登録処理 for (int i=args.Length()-1;i>=0;i--) { String::Value className(args[i]); tTJSVariant classObj; TVPExecuteExpression(*className, &classObj); if (classObj.Type() == tvtObject && TJS_SUCCEEDED(classObj.AsObjectClosureNoAddRef().IsInstanceOf(0,NULL,NULL,L"Class",NULL))) { MemberRegister *caller = new MemberRegister(isolate, classTemplate); tTJSVariantClosure closure(caller); classObj.AsObjectClosureNoAddRef().EnumMembers(TJS_IGNOREPROP, &closure, NULL); caller->Release(); } } // TJS機能メソッドを登録 Local<ObjectTemplate> protoTemplate = classTemplate->PrototypeTemplate(); protoTemplate->Set(String::NewFromUtf8(isolate, "tjsIsValid"), FunctionTemplate::New(isolate, tjsIsValid)); protoTemplate->Set(String::NewFromUtf8(isolate, "tjsOverride"), FunctionTemplate::New(isolate, tjsOverride)); args.GetReturnValue().Set(classTemplate->GetFunction()); }
// 実行ファイルがある場所に WHND を保存する void storeHWND(HWND hwnd) { tTJSVariant varScripts; TVPExecuteExpression(TJS_W("System.exeName"), &varScripts); ttstr path = varScripts; path += ".HWND"; IStream *stream = TVPCreateIStream(path, TJS_BS_WRITE); if (stream != NULL) { char buf[100]; DWORD len; _snprintf(buf, sizeof buf, "%d", (int)hwnd); stream->Write(buf, strlen(buf), &len); stream->Release(); } }
/** * 登録処理後 */ static void PostRegistCallback() { // Array.count を取得 { tTJSVariant varScripts; TVPExecuteExpression(TJS_W("Array"), &varScripts); iTJSDispatch2 *dispatch = varScripts.AsObjectNoAddRef(); tTJSVariant val; if (TJS_FAILED(dispatch->PropGet(TJS_IGNOREPROP, TJS_W("count"), NULL, &val, dispatch))) { TVPThrowExceptionMessage(L"can't get Array.count"); } ArrayCountProp = val.AsObject(); } }
//--------------------------------------------------------------------------- extern "C" __declspec(dllexport) HRESULT __stdcall V2Unlink() { if(TVPPluginGlobalRefCount > GlobalRefCountAtInit) return E_FAIL; // - まず、TJS のグローバルオブジェクトを取得する iTJSDispatch2 * global = TVPGetScriptDispatch(); if (global) { tTJSVariant varScripts; TVPExecuteExpression(TJS_W("System"), &varScripts); iTJSDispatch2 *dispatch = varScripts.AsObjectNoAddRef(); if (dispatch) { dispatch->DeleteMember(0, FPSLIMITNAME, NULL, dispatch); } global->Release(); } TVPRemoveContinuousEventHook(&limit); TVPUninitImportStub(); return S_OK; }
/** * クラスの登録 * @param HSQUIRRELVM v */ SQRESULT TJSObject::createTJSClass(HSQUIRRELVM v) { SQInteger top = sq_gettop(v); if (top < 2) { return sq_throwerror(v, _SC("invalid param")); } // クラスを生成 sq_pushobject(v, SQClassType<TJSObject>::ClassObject()); sq_newclass(v, true); // 継承する // メンバ登録 const tjs_char *tjsClassName = NULL; tTJSVariant tjsClassObj; for (SQInteger i=top; i>1; i--) { if ((tjsClassName = sqobject::getString(v,i))) { TVPExecuteExpression(tjsClassName, &tjsClassObj); if (tjsClassObj.Type() == tvtObject && TJS_SUCCEEDED(tjsClassObj.AsObjectClosureNoAddRef().IsInstanceOf(0,NULL,NULL,L"Class",NULL))) { MemberRegister *r = new MemberRegister(v, tjsClassObj); tTJSVariantClosure closure(r); tjsClassObj.AsObjectClosureNoAddRef().EnumMembers(TJS_IGNOREPROP, &closure, NULL); r->Release(); } } } if (tjsClassName) { // コンストラクタ登録 sq_pushstring(v, _SC("constructor"), -1); sq_pushvariant(v, tjsClassObj); sq_newclosure(v, tjsConstructor, 1); sq_createslot(v, -3); // クラス属性に tjsクラスを登録 sq_pushnull(v); sq_newtable(v); if (SQ_SUCCEEDED(sq_setattributes(v,-3))) { sq_pop(v,1); sq_pushnull(v); if (SQ_SUCCEEDED(sq_getattributes(v, -2))) { sq_pushstring(v, tjsClassAttrName, -1); sq_pushvariant(v, tjsClassObj); if (SQ_SUCCEEDED(sq_createslot(v, -3))) { sq_pop(v,1); } else { sq_pop(v,2); } } else { // XXX sq_pop(v,1); } } else { // XXX sq_pop(v,2); } // TJS機能メソッドを登録 sq_pushstring(v, _SC("tjsIsValid"), -1); sq_newclosure(v, TJSObject::tjsIsValid, 0); sq_createslot(v, -3); sq_pushstring(v, _SC("tjsOverride"), -1); sq_newclosure(v, TJSObject::tjsOverride, 0); sq_setparamscheck(v, -2, _SC(".sc")); sq_createslot(v, -3); } return 1; }