Mercurial Hosting > luan
comparison src/luan/modules/PackageLuan.java @ 798:9eccfede1094
fix cloning bug
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 06 Sep 2016 12:23:03 -0600 |
parents | c49980cdece6 |
children | 9c13a15a4002 |
comparison
equal
deleted
inserted
replaced
797:86e477945676 | 798:9eccfede1094 |
---|---|
6 import luan.Luan; | 6 import luan.Luan; |
7 import luan.LuanState; | 7 import luan.LuanState; |
8 import luan.LuanTable; | 8 import luan.LuanTable; |
9 import luan.LuanFunction; | 9 import luan.LuanFunction; |
10 import luan.LuanJavaFunction; | 10 import luan.LuanJavaFunction; |
11 import luan.LuanCloner; | |
11 import luan.LuanException; | 12 import luan.LuanException; |
12 | 13 |
13 | 14 |
14 public final class PackageLuan { | 15 public final class PackageLuan { |
15 | 16 |
84 } catch(IOException e) { | 85 } catch(IOException e) { |
85 throw new LuanException(e); | 86 throw new LuanException(e); |
86 } | 87 } |
87 } | 88 } |
88 | 89 |
89 public static boolean wouldLoad(LuanState luan,String modName) throws LuanException { | 90 private static boolean wouldLoad(LuanState luan,String modName) throws LuanException { |
90 LuanTable loaded = loaded(luan); | 91 LuanTable loaded = loaded(luan); |
91 if( loaded.rawGet(modName) != null ) | 92 if( loaded.rawGet(modName) != null ) |
92 return false; | 93 return false; |
93 if( modName.startsWith("java:") ) | 94 if( modName.startsWith("java:") ) |
94 return true; | 95 return true; |
101 } catch(IOException e) { | 102 } catch(IOException e) { |
102 throw new LuanException(e); | 103 throw new LuanException(e); |
103 } | 104 } |
104 } | 105 } |
105 | 106 |
107 public static void enableLoad(LuanState luan,String... mods) throws LuanException { | |
108 if( luan.isLocked ) { | |
109 for( String mod : mods ) { | |
110 if( wouldLoad(luan,mod) ) { | |
111 luan.isLocked = false; | |
112 luan.deepenClone(luan,new LuanCloner(LuanCloner.Type.COMPLETE)); | |
113 return; | |
114 } | |
115 } | |
116 } | |
117 } | |
118 | |
106 } | 119 } |