CreateContext() public static method

public static CreateContext ( ) : ScriptContext
return ScriptContext
Esempio n. 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);
     }
 }
Esempio n. 2
0
 public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
 {
     try
     {
         var func = GetFunction(binder.Name);
         if (func != null)
         {
             using (var ctx = ScriptEngine.CreateContext())
             {
                 ctx.ContextInfo = Name + "@" + binder.Name;
                 ctx.Prepare(func);
                 uint pos = 0;
                 foreach (var arg in args)
                 {
                     ctx.SetArg(pos++, arg);
                 }
                 ctx.Execute();
                 result = ctx.GetResult(func.ReturnTypeId);
                 return(true);
             }
         }
         else
         {
             ScriptEngine.Log("Unable to fetch global function: '{0}' from module '{1}'. Maybe it's overloaded?", Name);
             result = null;
             return(false);
         }
     }
     catch (Exception ex)
     {
         ScriptEngine.Log("Exception caught while calling into AngelScript runtime: {0}.", ex.Message);
         result = null;
         return(false);
     }
 }