@@ -24,18 +24,13 @@ NavigationStatus RequireVfs::reset(lua_State* L, std::string_view requirerChunkn
24
24
vfsType = VFSType::Std;
25
25
return stdLibVfs.resetToPath (std::string (requirerChunkname.substr (1 )));
26
26
}
27
- else
28
- {
29
- vfsType = VFSType::Disk;
30
- if (requirerChunkname == " =stdin" )
31
- {
32
- return fileVfs.resetToStdIn ();
33
- }
34
- else if (!requirerChunkname.empty () && requirerChunkname[0 ] == ' @' )
35
- {
36
- return fileVfs.resetToPath (std::string (requirerChunkname.substr (1 )));
37
- }
38
- }
27
+
28
+ vfsType = VFSType::Disk;
29
+ if (requirerChunkname == " =stdin" )
30
+ return fileVfs.resetToStdIn ();
31
+
32
+ if (!requirerChunkname.empty () && requirerChunkname[0 ] == ' @' )
33
+ return fileVfs.resetToPath (std::string (requirerChunkname.substr (1 )));
39
34
40
35
return NavigationStatus::NotFound;
41
36
}
@@ -55,25 +50,35 @@ NavigationStatus RequireVfs::jumpToAlias(lua_State* L, std::string_view path)
55
50
return NavigationStatus::Success;
56
51
}
57
52
58
- if (vfsType == VFSType::Disk)
53
+ switch (vfsType)
54
+ {
55
+ case VFSType::Disk:
59
56
return fileVfs.resetToPath (std::string (path));
60
- else if (vfsType == VFSType::Std)
57
+ case VFSType::Std:
61
58
return stdLibVfs.resetToPath (std::string (path));
62
-
63
- return NavigationStatus::NotFound;
59
+ default :
60
+ return NavigationStatus::NotFound;
61
+ }
64
62
}
65
63
66
64
NavigationStatus RequireVfs::toParent (lua_State* L)
67
65
{
68
66
NavigationStatus status;
69
- if (vfsType == VFSType::Disk)
67
+
68
+ switch (vfsType)
69
+ {
70
+ case VFSType::Disk:
70
71
status = fileVfs.toParent ();
71
- else if (vfsType == VFSType::Std)
72
+ break ;
73
+ case VFSType::Std:
72
74
status = stdLibVfs.toParent ();
73
- else if (vfsType == VFSType::Lute)
75
+ break ;
76
+ case VFSType::Lute:
74
77
luaL_error (L, " cannot get the parent of @lute" );
75
- else
78
+ break ;
79
+ default :
76
80
return NavigationStatus::NotFound;
81
+ }
77
82
78
83
if (status == NavigationStatus::NotFound)
79
84
{
@@ -91,24 +96,36 @@ NavigationStatus RequireVfs::toChild(lua_State* L, std::string_view name)
91
96
{
92
97
atFakeRoot = false ;
93
98
94
- if (vfsType == VFSType::Disk)
99
+ switch (vfsType)
100
+ {
101
+ case VFSType::Disk:
95
102
return fileVfs.toChild (std::string (name));
96
- else if (vfsType == VFSType::Std)
103
+ case VFSType::Std:
97
104
return stdLibVfs.toChild (std::string (name));
98
- else if (vfsType == VFSType::Lute)
105
+ case VFSType::Lute:
99
106
luaL_error (L, " '%s' is not a lute library" , std::string (name).c_str ());
107
+ break ;
108
+ default :
109
+ break ;
110
+ }
100
111
101
112
return NavigationStatus::NotFound;
102
113
}
103
114
104
115
bool RequireVfs::isModulePresent (lua_State* L) const
105
116
{
106
- if (vfsType == VFSType::Disk)
117
+ switch (vfsType)
118
+ {
119
+ case VFSType::Disk:
107
120
return fileVfs.isModulePresent ();
108
- else if (vfsType == VFSType::Std)
121
+ case VFSType::Std:
109
122
return stdLibVfs.isModulePresent ();
110
- else if (vfsType == VFSType::Lute)
123
+ case VFSType::Lute:
111
124
luaL_error (L, " @lute is not requirable" );
125
+ break ;
126
+ default :
127
+ break ;
128
+ }
112
129
113
130
return false ;
114
131
}
@@ -117,55 +134,74 @@ std::string RequireVfs::getContents(lua_State* L, const std::string& loadname) c
117
134
{
118
135
std::optional<std::string> contents;
119
136
120
- if (vfsType == VFSType::Disk)
137
+ switch (vfsType)
138
+ {
139
+ case VFSType::Disk:
121
140
contents = fileVfs.getContents (loadname);
122
- else if (vfsType == VFSType::Std)
141
+ break ;
142
+ case VFSType::Std:
123
143
contents = stdLibVfs.getContents (loadname);
144
+ break ;
145
+ default :
146
+ break ;
147
+ }
124
148
125
149
return contents ? *contents : " " ;
126
150
}
127
151
128
152
std::string RequireVfs::getChunkname (lua_State* L) const
129
153
{
130
- if (vfsType == VFSType::Disk)
154
+ switch (vfsType)
155
+ {
156
+ case VFSType::Disk:
131
157
return " @" + fileVfs.getFilePath ();
132
- else if (vfsType == VFSType::Std)
158
+ case VFSType::Std:
133
159
return " @" + stdLibVfs.getIdentifier ();
134
-
135
- return " " ;
160
+ default :
161
+ return " " ;
162
+ }
136
163
}
137
164
138
165
std::string RequireVfs::getLoadname (lua_State* L) const
139
166
{
140
- if (vfsType == VFSType::Disk)
167
+ switch (vfsType)
168
+ {
169
+ case VFSType::Disk:
141
170
return fileVfs.getAbsoluteFilePath ();
142
- else if (vfsType == VFSType::Std)
171
+ case VFSType::Std:
143
172
return stdLibVfs.getIdentifier ();
144
-
145
- return " " ;
173
+ default :
174
+ return " " ;
175
+ }
146
176
}
147
177
148
178
std::string RequireVfs::getCacheKey (lua_State* L) const
149
179
{
150
- if (vfsType == VFSType::Disk)
180
+ switch (vfsType)
181
+ {
182
+ case VFSType::Disk:
151
183
return fileVfs.getAbsoluteFilePath ();
152
- else if (vfsType == VFSType::Std)
184
+ case VFSType::Std:
153
185
return stdLibVfs.getIdentifier ();
154
-
155
- return " " ;
186
+ default :
187
+ return " " ;
188
+ }
156
189
}
157
190
158
191
bool RequireVfs::isConfigPresent (lua_State* L) const
159
192
{
160
193
if (atFakeRoot)
161
194
return true ;
162
195
163
- if (vfsType == VFSType::Disk )
164
- return fileVfs. isConfigPresent ();
165
- else if (vfsType == VFSType::Std)
196
+ switch (vfsType)
197
+ {
198
+ case VFSType::Disk:
166
199
return fileVfs.isConfigPresent ();
167
-
168
- return false ;
200
+ case VFSType::Std:
201
+ return stdLibVfs.isConfigPresent ();
202
+ default :
203
+ return false ;
204
+ }
169
205
}
170
206
171
207
std::string RequireVfs::getConfig (lua_State* L) const
@@ -183,10 +219,17 @@ std::string RequireVfs::getConfig(lua_State* L) const
183
219
184
220
std::optional<std::string> configContents;
185
221
186
- if (vfsType == VFSType::Disk)
222
+ switch (vfsType)
223
+ {
224
+ case VFSType::Disk:
187
225
configContents = fileVfs.getConfig ();
188
- else if (vfsType == VFSType::Std)
226
+ break ;
227
+ case VFSType::Std:
189
228
configContents = stdLibVfs.getConfig ();
229
+ break ;
230
+ default :
231
+ break ;
232
+ }
190
233
191
234
return configContents ? *configContents : " " ;
192
235
}
0 commit comments