Skip to content

Commit 6cdd904

Browse files
committed
添加simpRequire函数
1 parent ddb8e6b commit 6cdd904

File tree

1 file changed

+46
-36
lines changed

1 file changed

+46
-36
lines changed

init.lua

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ function errorf(str,...) error(str:format(...)) end
207207
---@diagnostic disable-next-line
208208
function assertf(v,str,...) return v or error(str:format(...)) end
209209

210+
---Use `local require=requirePath(...)` to require modules in simpler way
211+
---@overload fun(loader:function):unknown
212+
---@param path string
213+
function simpRequire(path)
214+
return type(path)=='function' and
215+
function(module) return path(module) end or
216+
function(module) return require(path..module) end
217+
end
218+
210219
-- Inside values
211220
local mainLoopStarted=false
212221
local autoGCcount=0
@@ -251,49 +260,50 @@ local onQuit=NULL
251260
local drawSysInfo=NULL
252261

253262
--------------------------------------------------------------
263+
local require=simpRequire('Zenitha.')
254264

255265
-- Extended lua basic libraries
256-
MATH= require'Zenitha.mathExtend'
257-
STRING= require'Zenitha.stringExtend'
258-
TABLE= require'Zenitha.tableExtend'
266+
MATH= require'mathExtend'
267+
STRING= require'stringExtend'
268+
TABLE= require'tableExtend'
259269

260270
-- Pure lua modules (simple)
261-
COLOR= require'Zenitha.color'
262-
DEBUG= require'Zenitha.debug'
263-
LOG= require'Zenitha.log'
264-
JSON= require'Zenitha.json'
271+
COLOR= require'color'
272+
DEBUG= require'debug'
273+
LOG= require'log'
274+
JSON= require'json'
265275

266276
-- Pure lua modules (complex, with update/draw)
267-
LANG= require'Zenitha.languages'
268-
REQUIRE= require'Zenitha.require'
269-
PROFILE= require'Zenitha.profile'
270-
TASK= require'Zenitha.task'
271-
HASH= require'Zenitha.sha2'
277+
LANG= require'languages'
278+
REQUIRE= require'require'
279+
PROFILE= require'profile'
280+
TASK= require'task'
281+
HASH= require'sha2'
272282

273283
-- Love-based modules (simple)
274-
VIB= require'Zenitha.vibrate'
275-
WHEELMOV= require'Zenitha.wheelToArrow'
276-
FONT= require'Zenitha.font'
277-
IMG= require'Zenitha.image'
278-
FILE= require'Zenitha.file'
279-
SCR= require'Zenitha.screen'
280-
GC= require'Zenitha.gcExtend'
281-
TCP= require'Zenitha.tcp'
282-
MIDI= require'Zenitha.midi'
284+
VIB= require'vibrate'
285+
WHEELMOV= require'wheelToArrow'
286+
FONT= require'font'
287+
IMG= require'image'
288+
FILE= require'file'
289+
SCR= require'screen'
290+
GC= require'gcExtend'
291+
TCP= require'tcp'
292+
MIDI= require'midi'
283293

284294
-- Love-based modules (complex, with update/draw)
285-
HTTP= require'Zenitha.http'
286-
SCN= require'Zenitha.scene'
287-
TEXT= require'Zenitha.text'
288-
SYSFX= require'Zenitha.sysFX'
289-
TWEEN= require'Zenitha.tween'
290-
WAIT= require'Zenitha.wait'
291-
MSG= require'Zenitha.message'
292-
BG= require'Zenitha.background'
293-
WIDGET= require'Zenitha.widget'
294-
SFX= require'Zenitha.sfx'
295-
BGM= require'Zenitha.bgm'
296-
VOC= require'Zenitha.voice'
295+
HTTP= require'http'
296+
SCN= require'scene'
297+
TEXT= require'text'
298+
SYSFX= require'sysFX'
299+
TWEEN= require'tween'
300+
WAIT= require'wait'
301+
MSG= require'message'
302+
BG= require'background'
303+
WIDGET= require'widget'
304+
SFX= require'sfx'
305+
BGM= require'bgm'
306+
VOC= require'voice'
297307

298308
--------------------------------------------------------------
299309

@@ -1198,6 +1208,6 @@ end
11981208
--------------------------------------------------------------
11991209

12001210
SCN.add('_quit',{enter=function() onQuit() love.event.quit() end})
1201-
SCN.add('_console',require'Zenitha/scene/console')
1202-
SCN.add('_zenitha',require'Zenitha/scene/demo')
1203-
SCN.add('_test',require'Zenitha/scene/test')
1211+
SCN.add('_console',require'scene/console')
1212+
SCN.add('_zenitha',require'scene/demo')
1213+
SCN.add('_test',require'scene/test')

0 commit comments

Comments
 (0)