Permalink
Browse files

Syncing with official mudlet-lua

  • Loading branch information...
1 parent c4f1923 commit 3aabb78c23395b15966a767bd4860c5b76cbaadf @Beliaar committed May 31, 2011
Showing with 49 additions and 6 deletions.
  1. +49 −6 lua/LuaGlobal.lua
View
@@ -5,14 +5,13 @@
if package.loaded["rex_pcre"] then rex = require "rex_pcre" end
if package.loaded["lpeg"] then lpeg = require "lpeg" end
+if package.loaded["zip"] then zip = require "zip" end
+if package.loaded["lfs"] then lfs = require "lfs" end
+
-- TODO this is required by DB.lua, so we might load it all at one place
--if package.loaded["luasql.sqlite3"] then require "luasql.sqlite3" end
json_to_value = yajl.to_value
-
-
-
-
gmcp = {}
function __gmcp_merge_gmcp_sub_tables( a, key )
@@ -23,13 +22,57 @@ function __gmcp_merge_gmcp_sub_tables( a, key )
a.__needMerge = nil
end
+
+function unzip( what, dest )
+ cecho("\n<blue>unpacking package:<"..what.."< to <"..dest..">\n")
+ local z = zip.open( what )
+ local createdDirs = {}
+ for file in z:files() do
+ local _f, err = z:open( file.filename )
+ local _data = _f:read("*a")
+ local _path = dest .. file.filename
+ local _dir = string.split( file.filename, '/' )
+ local created = dest;
+ for k,v in ipairs( _dir ) do
+ if k < # _dir then
+ created = created .. '/'.. v;
+ if not table.contains( createdDirs, created ) then
+ table.insert( createdDirs, created );
+ lfs.mkdir( created );
+ cecho("<red>--> creating dir:" .. created .. "\n");
+ end
+ elseif file.uncompressed_size == 0 then
+ if not table.contains( createdDirs, created ) then
+ cecho("<red>--> creating dir:" .. file.filename .. "\n")
+ table.insert( createdDirs, created );
+ lfs.mkdir( file.filename )
+ end
+ end
+ end
+ local _path = dest .. file.filename
+ if file.uncompressed_size > 0 then
+ local out = io.open( _path, "wb" )
+ if out then
+ cecho("<green>unpacking file:".._path.."\n")
+ out:write( _data )
+ out:close()
+ else
+ echo("ERROR: can't write file:".._path.."\n")
+ end
+ end
+ _f:close();
+ end
+ z:close()
+end
+
+
+
function onConnect()
end
-function handleWindowResizeevent()
+function handleWindowResizeEvent()
end
-echo("\nLOADING LuaGlobal\n")
local packages = {
"StringUtils.lua",

0 comments on commit 3aabb78

Please sign in to comment.