예제 #1
0
 // EnumMember用繰り返し実行部
 // param[0] メンバ名
 // param[1] フラグ
 // param[2] メンバの値
 virtual tjs_error TJS_INTF_METHOD FuncCall( // function invocation
     tjs_uint32 flag,			// calling flag
     const tjs_char * membername,// member name ( NULL for a default member )
     tjs_uint32 *hint,			// hint for the member name (in/out)
     tTJSVariant *result,		// result
     tjs_int numparams,			// number of parameters
     tTJSVariant **param,		// parameters
     iTJSDispatch2 *objthis		// object as "this"
 ) {
     if (numparams > 1) {
         if (param[2]->Type() == tvtObject) {
             const tjs_char *name = param[0]->GetString();
             tTVInteger flag = param[1]->AsInteger();
             bool staticMember = (flag & TJS_STATICMEMBER) != 0;
             iTJSDispatch2 *member = param[2]->AsObjectNoAddRef();
             if (member) {
                 if (TJS_SUCCEEDED(member->IsInstanceOf(0,NULL,NULL,L"Function",NULL))) {
                     registerFunction(name, *param[2], staticMember);
                 } else if (TJS_SUCCEEDED(member->IsInstanceOf(0,NULL,NULL,L"Property",NULL))) {
                     registerProperty(name, *param[2], staticMember);
                 }
             } else {
                 registNull(name);
             }
         }
     }
     if (result) {
         *result = true;
     }
     return TJS_S_OK;
 }
예제 #2
0
/**
 * missing 処理用の口
 * TJSインスタンスにメンバが存在しなかった場合は javascriptインスタンスを参照する
 */
tjs_error TJSInstance::missing(tjs_uint32 flag, const tjs_char * membername, tjs_uint32 *hint,
							 tTJSVariant *result,
							 tjs_int numparams, tTJSVariant **params, iTJSDispatch2 *objthis) {
	
	if (numparams < 3) {return TJS_E_BADPARAMCOUNT;};
	iTJSNativeInstance *ninstance;
	if (TJS_SUCCEEDED(objthis->NativeInstanceSupport(TJS_NIS_GETINSTANCE, classId, &ninstance))) {
		TJSInstance *self = (TJSInstance*)ninstance;
		HandleScope handle_scope(self->isolate);
		bool ret = false;
		if (!(int)*params[0]) { // get
			tTJSVariant result;
			if (TJS_SUCCEEDED(getProp(self->isolate, self->getObject(), params[1]->GetString(), &result))) {
				params[2]->AsObjectClosureNoAddRef().PropSet(0, NULL, NULL, &result, NULL);
				ret = true;
			}
		} else { // set
			if (TJS_SUCCEEDED(setProp(self->isolate, self->getObject(), params[1]->GetString(), params[2]))) {
				ret = true;
			}
		}
		if (result) {
			*result = ret;
		}
	}
	return TJS_E_NATIVECLASSCRASH;
}
예제 #3
0
// メソッドの呼び出し
void
TJSObject::caller(const FunctionCallbackInfo<Value>& args)
{
	Isolate *isolate = args.GetIsolate();
	HandleScope handle_scope(isolate);
	tTJSVariant self;
	if (getVariant(isolate, self, args.This())) {
		Local<Value> ret;
		
		// 引数変換
		tjs_int argc = args.Length();
		tTJSVariant **argv = new tTJSVariant*[argc];
		for (tjs_int i=0;i<argc;i++) {
			argv[i] = new tTJSVariant();
			*argv[i] = toVariant(isolate, args[i]);
		}

		if (self.AsObjectClosureNoAddRef().IsInstanceOf(0, NULL, NULL, L"Class", NULL) == TJS_S_TRUE) {
			// クラスオブジェクトならコンストラクタ呼び出し
			iTJSDispatch2 *instance = NULL;
			tjs_error error;
			if (TJS_SUCCEEDED(error = self.AsObjectClosureNoAddRef().CreateNew(0, NULL, NULL, &instance, argc, argv, NULL))) {
				ret = toJSValue(isolate, tTJSVariant(instance, instance));
				instance->Release();
			} else {
				ret = ERROR_KRKR(isolate, error);
			}
		} else {
			// メソッド呼び出し
			tTJSVariant result;
			tjs_error error;
			if (TJS_SUCCEEDED(error = self.AsObjectClosureNoAddRef().FuncCall(0, NULL, NULL, &result, argc, argv, NULL))) {
				ret = toJSValue(isolate, result);
			} else {
				ret = ERROR_KRKR(isolate, error);
			}
		}

		// 引数解放
		if (argv) {
			for (int i=0;i<argc;i++) {
				delete argv[i];
			}
			delete[] argv;
		}
		
		args.GetReturnValue().Set(ret);
		return;
	}
	args.GetReturnValue().Set(ERROR_BADINSTANCE(isolate));
}
예제 #4
0
// メソッドの呼び出し
Handle<Value>
TJSObject::caller(const Arguments& args)
{
	tTJSVariant self;
	if (getVariant(self, args.This())) {
		Handle<Value> ret;
		
		// 引数変換
		tjs_int argc = args.Length();
		tTJSVariant **argv = new tTJSVariant*[argc];
		for (tjs_int i=0;i<argc;i++) {
			argv[i] = new tTJSVariant();
			*argv[i] = toVariant(args[i]);
		}

		if (self.AsObjectClosureNoAddRef().IsInstanceOf(0, NULL, NULL, L"Class", NULL) == TJS_S_TRUE) {
			// クラスオブジェクトならコンストラクタ呼び出し
			iTJSDispatch2 *instance = NULL;
			tjs_error error;
			if (TJS_SUCCEEDED(error = self.AsObjectClosureNoAddRef().CreateNew(0, NULL, NULL, &instance, argc, argv, NULL))) {
				ret = toJSValue(tTJSVariant(instance, instance));
				instance->Release();
			} else {
				ret = ERROR_KRKR(error);
			}
		} else {
			// メソッド呼び出し
			tTJSVariant result;
			tjs_error error;
			if (TJS_SUCCEEDED(error = self.AsObjectClosureNoAddRef().FuncCall(0, NULL, NULL, &result, argc, argv, NULL))) {
				ret = toJSValue(result);
			} else {
				ret = ERROR_KRKR(error);
			}
		}

		// 引数解放
		if (argv) {
			for (int i=0;i<argc;i++) {
				delete argv[i];
			}
			delete[] argv;
		}
		
		return ret;
	}
	return ERROR_BADINSTANCE();
}
예제 #5
0
파일: Main.cpp 프로젝트: John-He-928/krkrz
//---------------------------------------------------------------------------
// visualization 用のサンプルデータを取得
//---------------------------------------------------------------------------
static void GetVisBuffer(iTJSDispatch2 * obj, tjs_int numsamples,
	tjs_int channels, tjs_int aheadsamples)
{
	if(SampleBuffer == NULL || SampleBufferLen != channels * numsamples)
	{
		if(SampleBuffer) delete [] SampleBuffer;
		SampleBuffer = new tjs_int16[SampleBufferLen = channels * numsamples];
	}

	tTJSVariant val[4];
	tTJSVariant *pval[4] = { val, val +1, val +2, val +3 };

	val[0] = (tjs_int64)(tjs_int)SampleBuffer;
	val[1] = (tjs_int64)numsamples;
	val[2] = (tjs_int64)channels;
	val[3] = (tjs_int64)aheadsamples;

	tTJSVariant res;

	static tjs_uint32 getVisBuffer_hint = 0;
	if(TJS_SUCCEEDED(obj->FuncCall(0, L"getVisBuffer", &getVisBuffer_hint,
		&res, 4, pval, obj)))
	{
		tjs_int ret = res;
		if(ret < numsamples)
		{
			ZeroMemory(SampleBuffer, sizeof(tjs_int16) * SampleBufferLen);
		}
	}
}
예제 #6
0
파일: Main.cpp 프로젝트: John-He-928/krkrz
	/**
	 * save 形式での辞書または配列の保存
	 * @param filename ファイル名
	 * @param utf true なら UTF-8 で出力
	 * @param newline 改行コード 0:CRLF 1:LF
	 * @return 実行結果
	 */
	static tjs_error TJS_INTF_METHOD save2(tTJSVariant *result,
										   tjs_int numparams,
										   tTJSVariant **param,
										   iTJSDispatch2 *objthis) {
		if (numparams < 1) return TJS_E_BADPARAMCOUNT;
		IFileWriter writer(param[0]->GetString(),
						   numparams > 1 ? (int)*param[1] != 0: false,
						   numparams > 2 ? (int)*param[2] : 0
						   );
                writer.hex = true;
		tjs_int count = 0;
		{
			tTJSVariant result;
			if (TJS_SUCCEEDED(ArrayCountProp->PropGet(0, NULL, NULL, &result, objthis))) {
				count = result;
			}
		}
		for (tjs_int i=0; i<count; i++) {
			tTJSVariant result;
			if (objthis->PropGetByNum(TJS_IGNOREPROP, i, &result, objthis) == TJS_S_OK) {
				writer.write(result.GetString());
				writer.newline();
			}
		}
		return TJS_S_OK;
	}
예제 #7
0
파일: main.cpp 프로젝트: xmoeproject/X-moe
/**
 * サンプル値の取得(旧方式)
 * 現在の再生位置から指定数のサンプルを取得してその平均値を返します。
 * 値が負のサンプル値は無視されます。
 * @param n 取得するサンプルの数。省略すると 100
 */
tjs_error
getSample(tTJSVariant *result,tjs_int numparams, tTJSVariant **param, iTJSDispatch2 *objthis)
{
	tjs_error ret = TJS_S_OK;
	tjs_int n = numparams > 0 ? (tjs_int)*param[0] : 100;
	if (n > 0 && result) {
		short *buf = (short*)malloc(n * sizeof(*buf));
		if (buf) {
			tTJSVariant buffer     = (tjs_int)buf;
			tTJSVariant numsamples = n;
			tTJSVariant channel    = 1;
			tTJSVariant *p[3] = {&buffer, &numsamples, &channel};
			if (TJS_SUCCEEDED(ret = objthis->FuncCall(0, L"getVisBuffer", NULL, NULL, 3, p, objthis))) {
				int c=0;
				int sum = 0;
				for (int i=0;i<n;i++) {
					if (buf[i] >= 0) {
						sum += buf[i]; c++;
					}
				}
				*result = c>0 ? sum / c : 0;
			}
			free(buf);
		}
	}
	return ret;
}
예제 #8
0
	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 :"));
	}
예제 #9
0
	void _TryExec() {
		tjs_error error;
		tTJSVariant r;
		if (TJS_SUCCEEDED(error = method.AsObjectNoAddRef()->FuncCall(0, NULL, NULL, &r, argc, argv, instance.AsObjectNoAddRef()))) {
			ret = toJSValue(args.GetIsolate(), r);
		} else {
			ret = ERROR_KRKR(args.GetIsolate(), error);
		}
	}
예제 #10
0
	void _TryGetter() {
		tjs_error error;
		tTJSVariant r;
		if (TJS_SUCCEEDED(error = method.AsObjectNoAddRef()->PropGet(0, NULL, NULL, &r, instance.AsObjectNoAddRef()))) {
			ret = toJSValue(info.GetIsolate(), r);
		} else {
			ret = ERROR_KRKR(info.GetIsolate(), error);
		}
	}
예제 #11
0
void tTJSBinarySerializer::InsertArray( tTJSArrayObject* array, tjs_uint index, tTJSVariant* value ) {
	if( value == NULL ) TJS_eTJSError( TJSReadError );
	tTJSArrayNI* ni = NULL;
	tjs_error hr = array->NativeInstanceSupport(TJS_NIS_GETINSTANCE, TJSGetArrayClassID(), (iTJSNativeInstance**)&ni );
	if( TJS_SUCCEEDED(hr) ) {
		// array->Insert( ni, *value, index );
		array->Add( ni, *value );
	}
}
예제 #12
0
//---------------------------------------------------------------------------
tjs_error TJS_INTF_METHOD
tTJSNativeClass::CreateNew(tjs_uint32 flag, const tjs_char * membername,
	tjs_uint32 *hint,
	iTJSDispatch2 **result, tjs_int numparams, tTJSVariant **param,
	iTJSDispatch2 *objthis)
{
	// CreateNew
	iTJSDispatch2 *superinst = NULL;
	if( SuperClass != NULL && membername == NULL ) {
		tjs_error hr = SuperClass->CreateNew( flag, membername, hint, &superinst, numparams, param, objthis );
		if(TJS_FAILED(hr)) {
			superinst = NULL;
		}
	}

	iTJSDispatch2 *dsp = CreateBaseTJSObject();

	tjs_error hr;
	try
	{
		// set object type for debugging
		if(TJSObjectHashMapEnabled())
			TJSObjectHashSetType(dsp, TJS_W("instance of class ") + ClassName);

		// instance initialization
		hr = FuncCall(0, NULL, NULL, NULL, 0, NULL, dsp); // add member to dsp

		if(TJS_FAILED(hr)) return hr;

		if( superinst != NULL ) {
			tTJSVariant param(superinst,superinst);
			dsp->ClassInstanceInfo( TJS_CII_SET_SUPRECLASS, 0, &param );
			superinst->Release();
			superinst = NULL;
		}

		hr = FuncCall(0, ClassName.c_str(), ClassName.GetHint(), NULL, numparams, param, dsp);
			// call the constructor
		if(hr == TJS_E_MEMBERNOTFOUND) hr = TJS_S_OK;
			// missing constructor is OK ( is this ugly ? )
	}
	catch(...)
	{
		dsp->Release();
		if( superinst ) superinst->Release();
		throw;
	}

	if(TJS_SUCCEEDED(hr)) {
		*result = dsp;
	} else if( superinst ) {
		superinst->Release();
	}
	return hr;
}
예제 #13
0
 void _TryCreate() {
     tjs_error error;
     iTJSDispatch2 *newinstance;
     if (TJS_SUCCEEDED(error = instance.AsObjectClosureNoAddRef().CreateNew(0, NULL, NULL, &newinstance, argc, args, NULL))) {
         r = tTJSVariant(newinstance, newinstance);
         newinstance->Release();
         result = SQ_OK;
     } else {
         result = ERROR_KRKR(v, error);
     }
 }
예제 #14
0
	void _TryCreate() {
		tjs_error error;
		iTJSDispatch2 *newinstance;
		if (TJS_SUCCEEDED(error = classObj.AsObjectClosureNoAddRef().CreateNew(0, NULL, NULL, &newinstance, argc, argv, NULL))) {
			new TJSInstance(args.GetIsolate(), args.This(), tTJSVariant(newinstance, newinstance));
			newinstance->Release();
			ret = args.This();
		} else {
			ret = ERROR_KRKR(args.GetIsolate(), error);
		}
	}
예제 #15
0
 void _TryGetter() {
     tjs_error error;
     tTJSVariant prop;
     if (SQ_SUCCEEDED(result = sq_getvariant(v, -1, &prop))) {
         if (TJS_SUCCEEDED(error = prop.AsObjectNoAddRef()->PropGet(0, NULL, NULL, &r, instance.AsObjectNoAddRef()))) {
             sq_pushvariant(v, r);
             result = 1;
         } else {
             result = ERROR_KRKR(v, error);
         }
     }
 }
예제 #16
0
 void _TrySetter() {
     sq_getvariant(v, 2, &r);
     tjs_error error;
     tTJSVariant prop;
     if (SQ_SUCCEEDED(result = sq_getvariant(v, -1, &prop))) {
         if (TJS_SUCCEEDED(error = prop.AsObjectNoAddRef()->PropSet(TJS_MEMBERENSURE, NULL, NULL, &r, instance.AsObjectNoAddRef()))) {
             result = SQ_OK;
         } else {
             result = ERROR_KRKR(v, error);
         }
     }
 }
예제 #17
0
파일: xml.cpp 프로젝트: xmoeproject/X-moe
/**
 * tTJSVariant を XMLノードに変換
 * @param var 変換元の値
 * @param doc XMLドキュメント
 * @return 作成したノード
 */
static xml_node *
createNodeFromVariant(tTJSVariant &var, xml_document &doc)
{
	switch(var.Type()) {
	case tvtObject:
		{
			iTJSDispatch2 *obj = var.AsObjectNoAddRef();
			if (obj == NULL) {
				// NULL
				return doc.allocate_node(rapidxml::node_element, L"null");
			} else if (obj->IsInstanceOf(TJS_IGNOREPROP,NULL,NULL,L"Array",obj) == TJS_S_TRUE) {
				// 配列
				xml_node *node = doc.allocate_node(rapidxml::node_element, L"array");
				tjs_int count = 0;
				{
					tTJSVariant result;
					if (TJS_SUCCEEDED(obj->PropGet(0, L"count", NULL, &result, obj))) {
						count = result;
					}
				}
				for (tjs_int i=0; i<count; i++) {
					tTJSVariant result;
					if (obj->PropGetByNum(TJS_IGNOREPROP, i, &result, obj) == TJS_S_OK) {
						xml_node *prop = doc.allocate_node(rapidxml::node_element, L"property");
						prop->append_attribute(doc.allocate_attribute(L"id", ttstr(i).c_str()));
						prop->append_node(createNodeFromVariant(result, doc));
						node->append_node(prop);
					}
				}
				return node;
			} else {
				// 辞書
				xml_node *node = doc.allocate_node(rapidxml::node_element, L"object");
				DictMemberDispCaller *caller = new DictMemberDispCaller(doc, node);
				tTJSVariantClosure closure(caller);
				obj->EnumMembers(TJS_IGNOREPROP, &closure, obj);
				caller->Release();
				return node;
			}
		}
		break;
	case tvtString:
		return doc.allocate_node(rapidxml::node_element, L"string", var.GetString());
	case tvtInteger:
	case tvtReal:
		return doc.allocate_node(rapidxml::node_element, L"number", ttstr(var).c_str());
	case tvtVoid:
		return doc.allocate_node(rapidxml::node_element, L"undefined");
	default:
		return doc.allocate_node(rapidxml::node_element, L"null");
	}
}
예제 #18
0
/**
 * 吉里吉里オブジェクトを javascriptオブジェクトに変換
 * @return 登録成功
 */
bool
TJSInstance::getJSObject(Local<Object> &result, const tTJSVariant &variant)
{
	iTJSDispatch2 *dispatch = variant.AsObjectNoAddRef();
	iTJSNativeInstance *ninstance;
	if (TJS_SUCCEEDED(dispatch->NativeInstanceSupport(TJS_NIS_GETINSTANCE, classId, &ninstance))) {
		// Javascript側から登録されたオブジェクトの場合は元の Javascriptオブジェクト情報をそのまま返す
		TJSInstance *self = (TJSInstance*)ninstance;
		result = self->getObject();
		return true;
	}
	return false;
}
예제 #19
0
/**
 * 吉里吉里オブジェクトを squirrel に登録。squirrel 側で生成されたオブジェクトの場合は元のオブジェクト情報をそのまま返す
 * @return 登録成功
 */
bool
TJSObject::pushVariant(HSQUIRRELVM v, tTJSVariant &variant)
{
    // 登録済みインスタンスかどうかの判定
    iTJSNativeInstance *ninstance;
    if (TJS_SUCCEEDED(variant.AsObjectNoAddRef()->NativeInstanceSupport(TJS_NIS_GETINSTANCE, classId, &ninstance))) {
        // 元々 squirrel 側から登録されたオブジェクトの場合は元の squirrel オブジェクト情報をそのまま返す
        TJSObject *self = (TJSObject*)ninstance;
        self->self.push(v);
        return true;
    }
    return false;
}
예제 #20
0
/**
 * call 処理用の口
 * TJSインスタンスからjavascriptインスタンスのメソッドを直接呼び出す
 */
tjs_error
TJSInstance::call(tjs_uint32 flag, const tjs_char * membername, tjs_uint32 *hint,
				tTJSVariant *result,
				tjs_int numparams, tTJSVariant **param, iTJSDispatch2 *objthis)
{
	if (numparams < 1) {return TJS_E_BADPARAMCOUNT;};
	iTJSNativeInstance *ninstance;
	if (TJS_SUCCEEDED(objthis->NativeInstanceSupport(TJS_NIS_GETINSTANCE, classId, &ninstance))) {
		TJSInstance *self = (TJSInstance*)ninstance;
		HandleScope handle_scope(self->isolate);
		return callMethod(self->isolate, self->getObject(), param[0]->GetString(), result, numparams-1, param+1, objthis);
	}
	return TJS_E_NATIVECLASSCRASH;
}
예제 #21
0
/**
 * TJSオブジェクトのオーバライド処理
 * 引数1 オブジェクト
 * 引数2 名前
 * 引数3 値。省略時は squirrel インスタンスから名前で参照
 */
SQRESULT
TJSObject::tjsOverride(HSQUIRRELVM v)
{
    SQRESULT result;
    tTJSVariant instance;
    if (getVariant(v,1,&instance) && instance.Type() == tvtObject) {
        tTJSVariant value;
        const SQChar *methodName = sqobject::getString(v,2);
        int n = sq_gettop(v);
        if (n >= 3) {
            // 引数で明示指定されている
            if (SQ_FAILED(result = sq_getvariant(v, 3, &value))) {
                return result;
            }
        } else {
            // 自己オブジェクトから名前で検索して登録
            sq_push(v, 1);
            sq_pushstring(v, methodName, -1);
            if (SQ_FAILED(result = sq_get(v, -2))) {
                sq_pop(v, 1); //self
                return result;
            } else {
                SQObjectType type = sq_gettype(v, -1);
                if (type == OT_CLOSURE || type == OT_NATIVECLOSURE) {
                    // クロージャの場合は bindenv しておく
                    sq_push(v, 1);
                    if (SQ_FAILED(result = sq_bindenv(v, -2))) {
                        sq_pop(v, 2); // func, self
                        return result;
                    } else {
                        sq_remove(v, -2); // original func
                    }
                }
                if (SQ_FAILED(result = sq_getvariant(v, -1, &value))) { // value
                    sq_pop(v, 1); //self
                    return result;
                }
                sq_pop(v, 1); // self
            }
        }
        tjs_error error;
        if (TJS_SUCCEEDED(error = instance.AsObjectClosureNoAddRef().PropSet(TJS_MEMBERENSURE, methodName, NULL, &value, NULL))) {
            return SQ_OK;
        } else {
            return  ERROR_KRKR(v, error);
        }
    }
    return ERROR_BADINSTANCE(v);
}
예제 #22
0
 void _TryExec() {
     tjs_error error;
     tTJSVariant method;
     if (SQ_SUCCEEDED(result = sq_getvariant(v, -1, &method))) {
         if (TJS_SUCCEEDED(error = method.AsObjectNoAddRef()->FuncCall(0, NULL, NULL, &r, argc, args, instance.AsObjectNoAddRef()))) {
             if (r.Type() != tvtVoid) {
                 sq_pushvariant(v, r);
                 result = 1;
             } else {
                 result = 0;
             }
         } else {
             result = ERROR_KRKR(v, error);
         }
     }
 }
예제 #23
0
// プロパティの設定
Handle<Value>
TJSObject::setter(Local<String> property, Local<Value> value, const AccessorInfo& info)
{
	tTJSVariant self;
	if (getVariant(self, info.This())) {
		String::Value propName(property);
		tTJSVariant param = toVariant(value);
		tjs_error error;
		if (TJS_SUCCEEDED(error = self.AsObjectClosureNoAddRef().PropSet(TJS_MEMBERENSURE, *propName, NULL, &param, NULL))) {
			return Undefined();
		} else {
			return ERROR_KRKR(error);
		}
	}
	return ERROR_BADINSTANCE();
}
예제 #24
0
// プロパティの設定
void
TJSObject::setter(Local<String> property, Local<Value> value, const PropertyCallbackInfo<Value>& info)
{
	Isolate *isolate = info.GetIsolate();
	HandleScope handle_scope(isolate);
	tTJSVariant self;
	if (getVariant(isolate, self, info.This())) {
		String::Value propName(property);
		tTJSVariant param = toVariant(isolate, value);
		tjs_error error;
		if (TJS_SUCCEEDED(error = self.AsObjectClosureNoAddRef().PropSet(TJS_MEMBERENSURE, *propName, NULL, &param, NULL))) {
		} else {
			info.GetReturnValue().Set(ERROR_KRKR(isolate, error));
		}
		return;
	}
	info.GetReturnValue().Set(ERROR_BADINSTANCE(isolate));
}
예제 #25
0
//---------------------------------------------------------------------------
void tTJSDictionaryNI::Assign(iTJSDispatch2 * dsp, bool clear)
{
	// copy members from "dsp" to "Owner"

	// determin dsp's object type
	tTJSArrayNI *arrayni = NULL;
	if(dsp && TJS_SUCCEEDED(dsp->NativeInstanceSupport(TJS_NIS_GETINSTANCE,
		TJSGetArrayClassID(), (iTJSNativeInstance**)&arrayni)) )
	{
		// convert from array
		if(clear) Owner->Clear();

		// reserve area
		tjs_int reqcount = Owner->Count + arrayni->Items.size();
		Owner->RebuildHash( reqcount );

		tTJSArrayNI::tArrayItemIterator i;
		for(i = arrayni->Items.begin(); i != arrayni->Items.end(); i++)
		{
			tTJSVariantString *name = i->AsStringNoAddRef();
			i++;
			if(arrayni->Items.end() == i) break;
			Owner->PropSetByVS(TJS_MEMBERENSURE|TJS_IGNOREPROP, name,
				&(*i),
				Owner);
		}
	}
	else
	{
		// otherwise
		if(clear) Owner->Clear();
		
		tSaveMemberCountCallback countCallback;
		dsp->EnumMembers(TJS_IGNOREPROP, &tTJSVariantClosure(&countCallback, NULL), dsp);
		tjs_int reqcount = countCallback.Count + Owner->Count;
		Owner->RebuildHash( reqcount );

		tAssignCallback callback;
		callback.Owner = Owner;

		dsp->EnumMembers(TJS_IGNOREPROP, &tTJSVariantClosure(&callback, NULL), dsp);

	}
}
예제 #26
0
/**
 * 吉里吉里クラスから 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());
}
예제 #27
0
	tjs_error TJS_INTF_METHOD StartTransition(
			/*in*/iTVPSimpleOptionProvider *options, // option provider
			/*in*/iTVPSimpleImageProvider *imagepro, // image provider
			/*in*/tTVPLayerType layertype, // destination layer type
			/*in*/tjs_uint src1w, tjs_uint src1h, // source 1 size
			/*in*/tjs_uint src2w, tjs_uint src2h, // source 2 size
			/*out*/tTVPTransType *type, // transition type
			/*out*/tTVPTransUpdateType * updatetype, // update typwe
			/*out*/iTVPBaseTransHandler ** handler // transition handler
			)
	{
		tjs_error er = tTVPCrossFadeTransHandlerProvider::StartTransition
			(options, imagepro, layertype, src1w, src1h, src2w, src2h,
			type, updatetype, handler);

		if(TJS_SUCCEEDED(er)) *updatetype = tutDivisible;

		return er;
	}
예제 #28
0
// プロパティの取得
Handle<Value>
TJSObject::getter(Local<String> property, const AccessorInfo& info)
{
	String::Value propName(property);
	if (wcscmp(*propName, TJSINSTANCENAME) == 0) {
		return Handle<Value>();
	}
	tTJSVariant self;
	if (getVariant(self, info.This())) {
		tjs_error error;
		tTJSVariant result;
		if (TJS_SUCCEEDED(error = self.AsObjectClosureNoAddRef().PropGet(0, *propName, NULL, &result, NULL))) {
			return toJSValue(result);
		} else {
			return ERROR_KRKR(error);
		}
	}
	return ERROR_BADINSTANCE();
}
예제 #29
0
/**
 * missing 処理用の口
 * TJSインスタンスにメンバが存在しなかった場合は squirrelインスタンスを参照する
 */
tjs_error TJSObject::missing(tjs_uint32 flag, const tjs_char * membername, tjs_uint32 *hint,
                             tTJSVariant *result,
                             tjs_int numparams, tTJSVariant **params, iTJSDispatch2 *objthis) {

    if (numparams < 3) {
        return TJS_E_BADPARAMCOUNT;
    };

    // バインドされている squirrel オブジェクトを取得
    iTJSNativeInstance *ninstance;
    if (TJS_SUCCEEDED(objthis->NativeInstanceSupport(TJS_NIS_GETINSTANCE, classId, &ninstance))) {
        TJSObject *self = (TJSObject*)ninstance;

        bool ret = false;
        HSQUIRRELVM gv = sqobject::getGlobalVM();
        if (!(int)*params[0]) { // get
            self->self.push(gv); // self
            sq_pushstring(gv, params[1]->GetString(), -1); // key
            if (SQ_SUCCEEDED(sq_get(gv, -2))) {
                tTJSVariant value;
                if (SQ_SUCCEEDED(sq_getvariant(gv, -1, &value))) {
                    params[2]->AsObjectClosureNoAddRef().PropSet(0, NULL, NULL, &value, NULL);
                    ret = true;
                }
                sq_pop(gv, 1); // value
            }
            sq_pop(gv, 1); // self
        } else { // set
            self->self.push(gv); // self
            sq_pushstring(gv, params[1]->GetString(), -1); // key
            sq_pushvariant(gv, *params[2]);    // value
            if (SQ_SUCCEEDED(sq_set(gv, -3))) {
                ret = true;
            }
            sq_pop(gv,1); // self
        }
        if (result) {
            *result = ret;
        }
    }
    return TJS_E_NATIVECLASSCRASH;
}
예제 #30
0
	tjs_error TJS_INTF_METHOD StartTransition(
			/*in*/iTVPSimpleOptionProvider *options, // option provider
			/*in*/iTVPSimpleImageProvider *imagepro, // image provider
			/*in*/tTVPLayerType layertype, // destination layer type
			/*in*/tjs_uint src1w, tjs_uint src1h, // source 1 size
			/*in*/tjs_uint src2w, tjs_uint src2h, // source 2 size
			/*out*/tTVPTransType *type, // transition type
			/*out*/tTVPTransUpdateType * updatetype, // update typwe
			/*out*/iTVPBaseTransHandler ** handler // transition handler
			)
	{
		if(type) *type = ttExchange; // transition type : exchange
		if(updatetype) *updatetype = tutDivisible;
			// update type : divisible
		if(!handler) return TJS_E_FAIL;
		if(!options) return TJS_E_FAIL;

		if(src1w != src2w || src1h != src2h)
			return TJS_E_FAIL; // src1 と src2 のサイズが一致していないと駄目


		// オプションを得る
		tTJSVariant tmp;
		tjs_uint64 time;
		tjs_int maxblocksize = 30;

		if(TJS_FAILED(options->GetValue(TJS_W("time"), &tmp)))
			return TJS_E_FAIL; // time 属性が指定されていない
		if(tmp.Type() == tvtVoid) return TJS_E_FAIL;
		time = (tjs_int64)tmp;
		if(time < 2) time = 2; // あまり小さな数値を指定すると問題が起きるので

		if(TJS_SUCCEEDED(options->GetValue(TJS_W("maxsize"), &tmp)))
			if(tmp.Type() != tvtVoid) maxblocksize = (tjs_int)tmp;

		// オブジェクトを作成
		*handler = new tTVPMosaicTransHandler(time, src1w, src1h, maxblocksize);

		return TJS_S_OK;
	}