/// <exception cref="Kirikiri.Tjs2.TJSException"></exception> /// <exception cref="Kirikiri.Tjs2.VariantException"></exception> public void AddArrayElement(Variant val) { string ss_add = "add"; Variant[] args = new Variant[1]; args[0] = val; mVal.AsObjectClosure().FuncCall(0, ss_add, null, args, null); }
public NativeClass(string name) : base() { mCallFinalize = false; mClassName = TJS.MapGlobalStringMap(name); mWorkParam = new Variant(); }
public virtual void PostClear() { mName = null; mValue = null; mValue = new Variant(); mSymFlags &= ~SYMBOL_USING; }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> /// <exception cref="Kirikiri.Tjs2.TJSException"></exception> public override int CreateNew(int flag, string membername, Holder<Dispatch2> result , Variant[] param, Dispatch2 objthis) { // CreateNew Dispatch2 dsp = CreateBaseTJSObject(); // instance initialization //int hr = funcCall( 0, null, null, null, dsp); // add member to dsp // 生成を高速化するためにメンバコピーを特别处理する形で实装 dsp.AddClassInstanveInfo(mClassName); NativeInstance nativeptr = CreateNativeInstance(); dsp.SetNativeInstance(mClassIDInternal, nativeptr); int hr = CopyAllMembers((CustomObject)dsp); if (hr < 0) { return hr; } hr = base.FuncCall(0, mClassName, null, param, dsp); // call constructor // call the constructor if (hr == Error.E_MEMBERNOTFOUND) { hr = Error.S_OK; } // missing constructor is OK ( is this ugly ? ) if (hr >= 0) { result.Set(dsp); } return hr; }
public RegExpNI() { mFlags = RegExpFlagToValue((char)0, 0); //mStart = 0; //mIndex =0; //mLastIndex = 0; mArray = new Variant(); }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> /// <exception cref="Kirikiri.Tjs2.TJSException"></exception> public override int FuncCall(int flag, string membername, Variant result, Variant [] param, Dispatch2 objthis) { if (membername != null) { return base.FuncCall(flag, membername, result, param, objthis); } return Process(result, param, objthis); }
// create new object /// <exception cref="Kirikiri.Tjs2.VariantException"></exception> /// <exception cref="Kirikiri.Tjs2.TJSException"></exception> public override int CreateNew(int flag, string memberName, Holder<Dispatch2> result , Variant[] param, Dispatch2 objThis) { if (IsNumber(memberName, Result)) { return CreateNewByNum(flag, Result[0], result, param, objThis); } return base.CreateNew(flag, memberName, result, param, objThis); }
public virtual void SelfClear() { mName = null; mHash = 0; mFlags = 0; mValue = new Variant(); mNext = null; mSymFlags = SYMBOL_INIT; }
/// <exception cref="Kirikiri.Tjs2.TJSException"></exception> /// <exception cref="Kirikiri.Tjs2.VariantException"></exception> public virtual int CreateNewByNum(int flag, int num, Holder<Dispatch2> result, Variant [] param, Dispatch2 objThis) { if (mObject == null) { throw new TJSException(Error.NullAccess); } return mObject.CreateNewByNum(flag, num, result, param, mObjThis != null ? mObjThis : (objThis != null ? objThis : mObject)); }
public override int PropSet(int flag, string membername, Variant param, Dispatch2 objThis) { if (membername != null) { return Error.E_MEMBERNOTFOUND; } mValue.Set(param); return Error.S_OK; }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> /// <exception cref="Kirikiri.Tjs2.TJSException"></exception> public override int CreateNew(int flag, string membername, Holder<Dispatch2> result , Variant[] param, Dispatch2 objthis) { int hr = base.CreateNew(flag, membername, result, param, objthis); if (hr == Error.E_MEMBERNOTFOUND && (flag & Interface.MEMBERMUSTEXIST) == 0) { return Error.E_INVALIDTYPE; } // call operation for void return hr; }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> /// <exception cref="Kirikiri.Tjs2.TJSException"></exception> public static void SaveStructuredDataForObject(Dispatch2 dsp, AList<Dispatch2> stack , TextWriteStreamInterface stream, string indentstr) { // check object recursion int count = stack.Count; for (int i = 0; i < count; i++) { Dispatch2 d = stack[i]; if (d == dsp) { // object recursion detected stream.Write("null /* object recursion detected */"); return; } } // determin dsp's object type DictionaryNI dicni; ArrayNI arrayni; if (dsp != null) { dicni = (DictionaryNI)dsp.GetNativeInstance(DictionaryClass.ClassID); if (dicni != null) { // dictionary stack.AddItem(dsp); dicni.SaveStructuredData(stack, stream, indentstr); stack.Remove(stack.Count - 1); return; } else { arrayni = (ArrayNI)dsp.GetNativeInstance(ArrayClass.ClassID); if (arrayni != null) { // array stack.AddItem(dsp); arrayni.SaveStructuredData(stack, stream, indentstr); stack.Remove(stack.Count - 1); return; } else { // other objects stream.Write("null /* (object) \""); // stored as a null Variant val = new Variant(dsp, dsp); stream.Write(LexBase.EscapeC(val.AsString())); stream.Write("\" */"); return; } } } stream.Write("null"); }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> /// <exception cref="Kirikiri.Tjs2.TJSException"></exception> public virtual int CreateNewByNum(int flag, int num, Holder<Dispatch2> result, Variant [] param, Dispatch2 objthis) { Dispatch2 OBJ1 = ((objthis != null) ? (objthis) : (mDispatch1)); int hr = mDispatch1.CreateNewByNum(flag, num, result, param, OBJ1); if (hr == Error.E_MEMBERNOTFOUND && mDispatch1 != mDispatch2) { Dispatch2 OBJ2 = ((objthis != null) ? (objthis) : (mDispatch2)); return mDispatch2.CreateNewByNum(flag, num, result, param, OBJ2); } return hr; }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> public static void CharacterCodeOf(Variant val) { string str = val.AsString(); if (str != null) { int v = str[0]; val.Set(v); } else { val.Set(0); } }
public override int PropGet(int flag, string membername, Variant result, Dispatch2 objthis) { if (membername != null) { return Error.E_MEMBERNOTFOUND; } if (result != null) { result.Set(mValue); } return Error.S_OK; }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> /// <exception cref="Kirikiri.Tjs2.TJSException"></exception> public override int PropGet(int flag, string membername, Variant result, Dispatch2 objthis) { int hr = base.PropGet(flag, membername, result, objthis); if (hr == Error.E_MEMBERNOTFOUND && (flag & Interface.MEMBERMUSTEXIST) == 0) { if (result != null) { result.Clear(); } // returns void return Error.S_OK; } return hr; }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> /// <exception cref="Kirikiri.Tjs2.TJSException"></exception> public TJS() { // create script cache object mCache = new ScriptCache(this); mPPValues = new Dictionary<string, int>(); SetPPValue("version", VERSION_HEX); SetPPValue("environment", ENV_JAVA_APPLICATION); // TODO 适切な值を入れる SetPPValue("compatibleSystem", 1); // 互换システム true mGlobal = new CustomObject(GLOBAL_HASH_BITS); mScriptBlocks = new AList<WeakReference<ScriptBlock>>(); Dispatch2 dsp; Variant val; // Array //dsp = new ArrayClass(); dsp = mArrayClass; val = new Variant(dsp, null); mGlobal.PropSet(MEMBERENSURE, "Array", val, mGlobal); // Dictionary //dsp = new DictionaryClass(); dsp = mDictionayClass; val = new Variant(dsp, null); mGlobal.PropSet(MEMBERENSURE, "Dictionary", val, mGlobal); // Date //TODO: add date back //dsp = new DateClass(); //val = new Variant(dsp, null); //mGlobal.PropSet(MEMBERENSURE, "Date", val, mGlobal); { // Math Dispatch2 math; dsp = math = new MathClass(); val = new Variant(dsp, null); mGlobal.PropSet(MEMBERENSURE, "Math", val, mGlobal); // Math.RandomGenerator dsp = new RandomGeneratorClass(); val = new Variant(dsp, null); math.PropSet(MEMBERENSURE, "RandomGenerator", val, math); } // Exception dsp = new ExceptionClass(); val = new Variant(dsp, null); mGlobal.PropSet(MEMBERENSURE, "Exception", val, mGlobal); // RegExp dsp = new RegExpClass(); val = new Variant(dsp, null); mGlobal.PropSet(MEMBERENSURE, "RegExp", val, mGlobal); }
protected internal override int Process(Variant result, Variant[] param, Dispatch2 objthis) { DictionaryNI _this = (DictionaryNI)objthis.GetNativeInstance(Kirikiri.Tjs2.DictionaryClass .ClassID); if (_this == null) { return Error.E_NATIVECLASSCRASH; } int hr = _this.Construct(param, objthis); if (hr < 0) { return hr; } return Error.S_OK; }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> /// <exception cref="Kirikiri.Tjs2.TJSException"></exception> public override int Operation(int flag, string membername, Variant result, Variant param, Dispatch2 objthis) { int hr = base.Operation(flag, membername, result, param, objthis); if (hr == Error.E_MEMBERNOTFOUND && (flag & Interface.MEMBERMUSTEXIST) == 0) { // value not found -> create a value, do the operation once more hr = base.PropSet(Interface.MEMBERENSURE, membername, VoidVal, objthis); if (hr < 0) { return hr; } hr = base.Operation(flag, membername, result, param, objthis); } return hr; }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> /// <exception cref="Kirikiri.Tjs2.TJSException"></exception> public override int FuncCall(int flag, string membername, Variant result, Variant [] param, Dispatch2 objthis) { if (membername != null) { return base.FuncCall(flag, membername, result, param, objthis); } if (objthis == null) { return Error.E_NATIVECLASSCRASH; } if (result != null) { result.Clear(); } return Process(result, param, objthis); }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> /// <exception cref="Kirikiri.Tjs2.TJSException"></exception> public override int PropGet(int flag, string membername, Variant result, Dispatch2 objthis) { if (membername != null) { return base.PropGet(flag, membername, result, objthis); } if (objthis == null) { return Error.E_NATIVECLASSCRASH; } if (result == null) { return Error.E_FAIL; } return Get(result, objthis); }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> /// <exception cref="Kirikiri.Tjs2.TJSException"></exception> public override int PropSet(int flag, string membername, Variant param, Dispatch2 objthis) { if (membername != null) { return base.PropSet(flag, membername, param, objthis); } if (objthis == null) { return Error.E_NATIVECLASSCRASH; } if (param == null) { return Error.E_FAIL; } return Set(param, objthis); }
public static string FormatString(string format, Variant[] @params) { int count = @params.Length; object[] args = new object[count]; for (int i = 0; i < count; i++) { args[i] = @params[i].ToJavaObject(); if (args[i] is string) { int length = ((string)args[i]).Length; if (length == 1) { args[i] = ((string)args[i])[0]; } } } return string.Format(format, args); }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> public static string VariantToExpressionString(Variant val) { // convert given variant to string which can be interpret as an expression. // this function does not convert objects ( returns empty string ) if (val.IsVoid()) { return "void"; } else { if (val.IsInteger()) { return val.AsString(); } else { if (val.IsReal()) { string s = Variant.RealToHexString(val.AsDouble()); return s + " /* " + val.AsString() + " */"; } else { if (val.IsString()) { string s = LexBase.EscapeC(val.AsString()); return "\"" + s + "\""; } else { if (val.IsOctet()) { string s = Variant.OctetToListString(val.AsOctet()); return "<%" + s + "%>"; } else { return string.Empty; } } } } } }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> /// <exception cref="Kirikiri.Tjs2.TJSException"></exception> public override int FuncCall(int flag, string membername, Variant result, Variant [] param, Dispatch2 objthis) { if (!GetValidity()) { return Error.E_INVALIDOBJECT; } if (membername != null) { return base.FuncCall(flag, membername, result, param, objthis); } // 生成を高速化するためにメンバコピーを特别处理する形で实装 objthis.AddClassInstanveInfo(mClassName); NativeInstance nativeptr = CreateNativeInstance(); objthis.SetNativeInstance(mClassIDInternal, nativeptr); int hr = CopyAllMembers((CustomObject)objthis); if (hr < 0) { return hr; } return Error.S_OK; }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> /// <exception cref="Kirikiri.Tjs2.TJSException"></exception> protected internal override int Process(Variant result, Variant[] param, Dispatch2 objthis) { Variant val = new Variant(string.Empty); if ((param.Length > 0) ? param[0].IsVoid() != true : false) { val.CopyRef(param[0]); } string message_name = "message"; objthis.PropSet(Interface.MEMBERENSURE, message_name, val, objthis); if ((param.Length > 1) ? param[1].IsVoid() != true : false) { val.CopyRef(param[1]); } else { val.Set(string.Empty); } string trace_name = "trace"; objthis.PropSet(Interface.MEMBERENSURE, trace_name, val, objthis); return Error.S_OK; }
public virtual bool Callback(string name, int flags, Variant value) { // hidden members are not processed if ((flags & Interface.HIDDENMEMBER) != 0) { return true; } // push items mItems.AddItem(new Variant(name)); mItems.AddItem(new Variant(value)); return true; }
public override int Construct(Variant[] param, Dispatch2 tjsObj) { // called by TJS constructor if (param != null && param.Length != 0) { return Error.E_BADPARAMCOUNT; } return Error.S_OK; }
// create new object by index number /// <exception cref="Kirikiri.Tjs2.VariantException"></exception> /// <exception cref="Kirikiri.Tjs2.TJSException"></exception> public override int CreateNewByNum(int flag, int num, Holder<Dispatch2> result, Variant [] param, Dispatch2 objthis) { if (!GetValidity()) { return Error.E_INVALIDOBJECT; } ArrayNI ni = (ArrayNI)objthis.GetNativeInstance(ArrayClass.ClassID); if (ni == null) { return Error.E_NATIVECLASSCRASH; } int membercount = ni.mItems.Count; if (num < 0) { num = membercount + num; } if ((flag & Interface.MEMBERMUSTEXIST) != 0 && (num < 0 || membercount <= num)) { return Error.E_MEMBERNOTFOUND; } Variant val = new Variant((membercount <= num || num < 0) ? VoidValue : ni.mItems [num]); return DefaultCreateNew(flag, val, result, param, objthis); }
public virtual int Remove(ArrayNI ni, Variant @ref, bool removeall) { int count = 0; IntVector todelete = new IntVector(); int arrayCount = ni.mItems.Count; for (int i = 0; i < arrayCount; i++) { Variant v = ni.mItems[i]; if (@ref.DiscernCompareInternal(v)) { count++; todelete.Add(i); if (!removeall) { break; } } } // list objects up int delCount = todelete.Size(); for (int i_1 = 0; i_1 < delCount; i_1++) { int pos = todelete.Get(i_1); Variant v = ni.mItems[pos]; v.Clear(); } // remove items found for (int i_2 = delCount - 1; i_2 >= 0; i_2--) { ni.mItems.Remove(todelete.Get(i_2)); } todelete = null; return count; }