public void PushMemberValue(MemberHandle handle) { PushSelf(); if (!VM.GetByHandleFixed(-1, handle).IsOK()) { VM.Pop(1); throw new Exception($"Unable to get member with handle {handle}"); } VM.RemoveFixed(-2); }
public object this[MemberHandle handle] { get { PushSelf(); if (!VM.GetByHandleFixed(-1, handle).IsOK()) { VM.Pop(1); throw new Exception($"Unable to get member with handle {handle}"); } var ret = VM.GetDynamic(-1); VM.Pop(2); return(ret); } set { PushSelf(); VM.PushDynamic(value); if (!VM.SetByHandleFixed(-2, handle).IsOK()) { VM.Pop(1); throw new Exception($"Unable to set member with handle {handle} to value {value}"); } VM.Pop(1); } /* * get * { * PushSelf(); * VM.PushDynamic(key); * if (!VM.GetFixed(-2).IsOK()) * { * VM.Pop(1); * throw new Exception($"Unable to get member/slot with key {key}"); * } * var ret = VM.GetDynamic(-1); * VM.Pop(2); * return ret; * } * set * { * PushSelf(); * VM.PushDynamic(key); * VM.PushDynamic(value); * if (!VM.SetFixed(-3).IsOK()) * { * throw new Exception($"Unable to set member/slot with key {key}"); * } * VM.Pop(1); * } */ }
public T Get <T>(MemberHandle handle) { var val = this[handle]; if (val is T already) { return(already); } try { return((T)val); } catch { try { return((T)Convert.ChangeType(val, typeof(T))); } catch { throw ScriptHandler.ErrorHelper.WrongMemberOrSlotType(handle, typeof(T).Name); } } }
public object[] CallMember(MemberHandle handle, params object[] arguments) { PushMemberValue(handle); PushSelf(); return(ScriptHandler.PopToCallAsMethod(-2, arguments)); }