public override bool TrySetMember(SetMemberBinder binder, object value) { IodineObject val = typeRegistry.ConvertToIodineObject(value); internalObject.SetAttribute(binder.Name, val); return(true); }
/// <summary> /// Calls an Iodine function in the current module /// </summary> /// <param name="name">Function name.</param> /// <param name="args">Arguments.</param> public dynamic Call(string name, params object[] args) { IodineObject[] arguments = new IodineObject[args.Length]; for (int i = 0; i < args.Length; i++) { arguments [i] = typeRegistry.ConvertToIodineObject(args [i]); } IodineObject ret = Context.Invoke(module.GetAttribute(name), arguments); return(IodineDynamicObject.Create(ret, Context.VirtualMachine, typeRegistry)); }
public static InternalMethodCallback Create(TypeRegistry registry, IEnumerable<MethodInfo> info, object self = null) { return new InternalMethodCallback (((VirtualMachine vm, IodineObject @this, IodineObject[] arguments) => { var suitableOverloads = info.Where (p => p.GetParameters ().Length == arguments.Length); foreach (MethodInfo overload in suitableOverloads) { var types = overload.GetParameters ().Select (p => p.ParameterType).ToArray (); object[] objects = new object[arguments.Length]; bool mappingExists = true; for (int i = 0; i < arguments.Length; i++) { if (!registry.TypeMappingExists (arguments [i].TypeDef, types [i])) { mappingExists = false; break; } objects [i] = registry.ConvertToNativeObject (arguments [i], types [i]); } if (mappingExists) { return registry.ConvertToIodineObject (overload.Invoke (self, objects)); } } // No suitable overload found Console.WriteLine ("No suitable overload found!"); return null; }), null); }
public static InternalMethodCallback Create(TypeRegistry registry, IEnumerable <MethodInfo> info, object self = null) { return(new InternalMethodCallback(((VirtualMachine vm, IodineObject @this, IodineObject[] arguments) => { var suitableOverloads = info.Where(p => p.GetParameters().Length == arguments.Length); foreach (MethodInfo overload in suitableOverloads) { var types = overload.GetParameters().Select(p => p.ParameterType).ToArray(); object[] objects = new object[arguments.Length]; bool mappingExists = true; for (int i = 0; i < arguments.Length; i++) { if (!registry.TypeMappingExists(arguments [i].TypeDef, types [i])) { mappingExists = false; break; } objects [i] = registry.ConvertToNativeObject(arguments [i], types [i]); } if (mappingExists) { return registry.ConvertToIodineObject(overload.Invoke(self, objects)); } } // No suitable overload found Console.WriteLine("No suitable overload found!"); return null; }), null)); }
public override IodineObject ConvertFrom(TypeRegistry registry, object obj) { object[] arr = (object[])obj; IodineObject[] iodineObjects = new IodineObject[arr.Length]; for (int i = 0; i < arr.Length; i++) { iodineObjects [i] = registry.ConvertToIodineObject (arr [i]); } return new IodineList (iodineObjects); }
public override IodineObject ConvertFrom(TypeRegistry registry, object obj) { object[] arr = (object[])obj; IodineObject[] iodineObjects = new IodineObject[arr.Length]; for (int i = 0; i < arr.Length; i++) { iodineObjects [i] = registry.ConvertToIodineObject(arr [i]); } return(new IodineList(iodineObjects)); }
public static InternalMethodCallback Create(TypeRegistry registry, MethodInfo info, object self = null) { return new InternalMethodCallback (((VirtualMachine vm, IodineObject @this, IodineObject[] arguments) => { Type[] types = info.GetParameters ().Select (p => p.ParameterType).ToArray (); int i = 0; object[] objects = arguments.Select (p => registry.ConvertToNativeObject (p, types [i++])).ToArray (); return registry.ConvertToIodineObject (info.Invoke (self, objects)); }), null); }
public static InternalMethodCallback Create(TypeRegistry registry, MethodInfo info, object self = null) { return(new InternalMethodCallback(((VirtualMachine vm, IodineObject @this, IodineObject[] arguments) => { Type[] types = info.GetParameters().Select(p => p.ParameterType).ToArray(); int i = 0; object[] objects = arguments.Select(p => registry.ConvertToNativeObject(p, types [i++])).ToArray(); return registry.ConvertToIodineObject(info.Invoke(self, objects)); }), null)); }
public IodineObject Get(VirtualMachine vm) { return(typeRegistry.ConvertToIodineObject(fieldInfo.GetValue(self))); }
public IodineObject Get(VirtualMachine vm) { return(typeRegistry.ConvertToIodineObject(propertyInfo.GetValue(self, null))); }