fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
ce74f10
v2.1.3
1local loader ={} 2 3local log =require ( "log" ) 4 5local notification =require ( "notification" ) 6local configdir =love . filesystem . getSaveDirectory () 7 8function loader . loadFile ( file , clonesTbl ) 9if file and love . filesystem . getInfo ( file , "file" ) then 10log . info ( "[CLONES] Load: %s/%s" , configdir , file ) 11 12local status , chunk =pcall ( love . filesystem . load , file ) 13 14if not status then 15-- Failed loading chunk, chunk is an error string 16log . error ( chunk ) 17notification . error ( chunk ) 18elseif chunk then 19-- Create a sandboxed lua environment 20local env ={} 21env . _G =env 22 23-- Set the loaded chunk inside the sandbox 24setfenv ( chunk , env ) 25 26local status , custom_clones =pcall ( chunk ) 27if not status then 28-- Failed calling the chunk, custom_clones is an error string 29log . error ( custom_clones ) 30notification . error ( custom_clones ) 31else 32local num_clones =0 33for clone_id , clones in pairs ( custom_clones ) do 34if type ( clones ) == "table" then 35clonesTbl [ clone_id ] ={} 36for version , info in pairs ( clones ) do 37if info . id and info . version then 38num_clones =num_clones + 1 39log . debug ( "[CLONES] %s[%d] = %s[%d]" , clone_id , version , info . id , info . version ) 40clonesTbl [ clone_id ][ version ] =info 41end 42end 43end 44end 45log . info ( "[CLONES] Loaded %d clones from %s" , num_clones , file ) 46notification . coloredMessage (( "Loaded %d clones from %s" ): format ( num_clones , file )) 47end 48end 49end 50end 51 52return loader