// メソッドの呼び出し 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)); }
// メソッドの呼び出し 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(); }
/** * TJSオブジェクトのオーバライド処理 * @param args 引数 * @return 結果 */ void TJSInstance::tjsOverride(const FunctionCallbackInfo<Value>& args) { Isolate *isolate = args.GetIsolate(); HandleScope handle_scope(isolate); tTJSVariant instance; if (getVariant(isolate, instance, args.This())) { if (args.Length() > 0) { Local<Value> func = args.Length() > 1 ? args[1] : args.This()->Get(args[0]); if (func->IsFunction()) { tTJSVariant value = toVariant(isolate, func->ToObject(), args.This()); String::Value methodName(args[0]); tjs_error error; if (TJS_FAILED(error = instance.AsObjectClosureNoAddRef().PropSet(TJS_MEMBERENSURE, *methodName, NULL, &value, NULL))) { args.GetReturnValue().Set(ERROR_KRKR(isolate, error)); return; } args.GetReturnValue().Set(Undefined(isolate)); return; } } args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "not function"))); return; } args.GetReturnValue().Set(ERROR_BADINSTANCE(isolate)); }
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); } }
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); } }
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); } }
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); } }
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); } } }
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); } } }
/** * 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); }
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); } } }
// プロパティの設定 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, ¶m, NULL))) { return Undefined(); } else { return ERROR_KRKR(error); } } return ERROR_BADINSTANCE(); }
// プロパティの設定 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, ¶m, NULL))) { } else { info.GetReturnValue().Set(ERROR_KRKR(isolate, error)); } return; } info.GetReturnValue().Set(ERROR_BADINSTANCE(isolate)); }
// プロパティの取得 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(); }
// プロパティの取得 void TJSObject::getter(Local<String> property, const PropertyCallbackInfo<Value>& info) { Isolate *isolate = info.GetIsolate(); HandleScope handle_scope(isolate); String::Value propName(property); if (wcscmp(*propName, TJSINSTANCENAME) == 0) { return; } tTJSVariant self; if (getVariant(isolate, self, info.This())) { tjs_error error; tTJSVariant result; if (TJS_SUCCEEDED(error = self.AsObjectClosureNoAddRef().PropGet(0, *propName, NULL, &result, NULL))) { info.GetReturnValue().Set(toJSValue(isolate, result)); } else { info.GetReturnValue().Set(ERROR_KRKR(isolate, error)); } return; } info.GetReturnValue().Set(ERROR_BADINSTANCE(isolate)); }