public override bool TrySetMember(SetMemberBinder binder, object value) { try { var prop = GetProperty(binder.Name); if (prop != null && prop.Setter != null) { using (var ctx = ScriptEngine.CreateContext()) { ctx.ContextInfo = objectType.Name + "::" + prop.Setter.Name; ctx.Prepare(prop.Setter); ctx.SetObject(thisptr); ctx.SetArg(0, value); ctx.Execute(); return(true); } } var field = GetField(binder.Name); if (field != null) { ScriptEngine.SetVariable(thisptr + field.Offset, field.TypeId, value); return(true); } ScriptEngine.Log("Unable to set member '{0}' on object of type '{1}'.", binder.Name, objectType.Name); return(false); } catch (Exception ex) { ScriptEngine.Log("Exception caught while getting object member: {0}.", ex.Message); return(false); } }
public override bool TrySetMember(SetMemberBinder binder, object value) { try { Variable variable; if (!variables.TryGetValue(binder.Name, out variable)) { int idx = GetGlobalVarIndexByName(binder.Name); var ptr = GetAddressOfGlobalVar(idx); if (ptr == IntPtr.Zero) { ScriptEngine.Log("Global variable does not exist."); return(false); } int tid; GetGlobalVar(idx, out tid); var instance = ScriptEngine.GetVariable(ptr, tid); variables[binder.Name] = variable = new Variable(instance, ptr, tid); } ScriptEngine.SetVariable(variable.Address, variable.TypeId, value); return(true); } catch (Exception ex) { ScriptEngine.Log("Exception caught while fetching '{0}' variable of module '{1}': {2}.", Name, binder.Name, ex.Message); return(false); } }