GetVariable() 공개 정적인 메소드

public static GetVariable ( IntPtr ptr, int tid, object cached = null ) : object
ptr System.IntPtr
tid int
cached object
리턴 object
예제 #1
0
 public override bool TryGetMember(GetMemberBinder binder, out object result)
 {
     try
     {
         var prop = GetProperty(binder.Name);
         if (prop != null && prop.Getter != null)
         {
             using (var ctx = ScriptEngine.CreateContext())
             {
                 ctx.ContextInfo = objectType.Name + "::" + prop.Getter.Name;
                 ctx.Prepare(prop.Getter);
                 ctx.SetObject(thisptr);
                 ctx.Execute();
                 result = ctx.GetResult(prop.Getter.ReturnTypeId);
                 return(true);
             }
         }
         var field = GetField(binder.Name);
         if (field != null)
         {
             result = ScriptEngine.GetVariable(thisptr + field.Offset, field.TypeId, field.Instance);
             return(true);
         }
         ScriptEngine.Log("Unable to get member '{0}' from object of type '{1}'.", binder.Name, objectType.Name);
         result = null;
         return(false);
     }
     catch (Exception ex)
     {
         ScriptEngine.Log("Exception caught while getting object member: {0}.", ex.Message);
         result = null;
         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);
     }
 }
예제 #3
0
        Field GetField(string name)
        {
            Field field = null;

            if (!Fields.TryGetValue(name, out field))
            {
                int tid;
                int offset;
                if (objectType.GetFieldDesc(name, out offset, out tid))
                {
                    var instance = ScriptEngine.GetVariable(thisptr + offset, tid);
                    field = new Field(offset, tid, instance);
                }
                Fields[name] = field;
            }
            return(field);
        }