本文整理汇总了C#中Iodine.Runtime.VirtualMachine.LoadModule方法的典型用法代码示例。如果您正苦于以下问题:C# VirtualMachine.LoadModule方法的具体用法?C# VirtualMachine.LoadModule怎么用?C# VirtualMachine.LoadModule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Iodine.Runtime.VirtualMachine
的用法示例。
在下文中一共展示了VirtualMachine.LoadModule方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: require
private IodineObject require(VirtualMachine vm, IodineObject self, IodineObject[] args)
{
if (args.Length < 1) {
vm.RaiseException (new IodineArgumentException (1));
return null;
}
IodineString path = args [0] as IodineString;
if (path == null) {
vm.RaiseException (new IodineTypeException ("Str"));
return null;
}
string name = path.Value;
string fullPath = Path.GetFullPath (name);
if (args.Length == 1) {
if (VirtualMachine.ModuleCache.ContainsKey (fullPath)) {
IodineModule module = VirtualMachine.ModuleCache [fullPath];
vm.Top.Module.SetAttribute (vm, Path.GetFileNameWithoutExtension (fullPath),
module);
} else {
IodineModule module = vm.LoadModule (name);
vm.Top.Module.SetAttribute (vm, Path.GetFileNameWithoutExtension (
fullPath), module);
VirtualMachine.ModuleCache [fullPath] = module;
module.Initializer.Invoke (vm, new IodineObject[] { });
}
} else {
IodineTuple names = args [1] as IodineTuple;
if (names == null) {
vm.RaiseException (new IodineTypeCastException ("Tuple"));
return null;
}
IodineModule module = null;
if (VirtualMachine.ModuleCache.ContainsKey (fullPath)) {
module = VirtualMachine.ModuleCache [fullPath];
} else {
module = vm.LoadModule (name);
VirtualMachine.ModuleCache [fullPath] = module;
module.Initializer.Invoke (vm, new IodineObject[] { });
}
vm.Top.Module.SetAttribute (vm, Path.GetFileNameWithoutExtension (fullPath),
module);
if (names.Objects.Length > 0) {
foreach (IodineObject item in names.Objects) {
vm.Top.Module.SetAttribute (vm, item.ToString (),
module.GetAttribute (item.ToString ()));
}
} else {
foreach (KeyValuePair<string, IodineObject> kv in module.Attributes) {
vm.Top.Module.SetAttribute (vm, kv.Key, kv.Value);
}
}
}
return null;
}