SetVariable() 공개 정적인 메소드

public static SetVariable ( IntPtr ptr, int tid, object value ) : void
ptr System.IntPtr
tid int
value object
리턴 void
예제 #1
0
 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);
     }
 }
예제 #2
0
 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);
     }
 }