Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

Commit

Permalink
Added a Visual Studio 2005 project, created a header file for Windows…
Browse files Browse the repository at this point in the history
… exports, added package meta-data to the gzio module and a README file for the root directory.
  • Loading branch information
Judge Maygarden committed Aug 20, 2007
1 parent 33a95e2 commit ec4899f
Show file tree
Hide file tree
Showing 6 changed files with 280 additions and 11 deletions.
6 changes: 6 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
gzio 0.9.0
------------------------------

The Lua gzip file I/O module emulates the standard I/O module, but operates on compressed gzip format files.

gzio is free software and uses the same license as Lua 5.1.
20 changes: 20 additions & 0 deletions mak.vs2005/gzio.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual C++ Express 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gzio", "gzio.vcproj", "{D4CCE010-CCD1-40B9-955D-0CF97DEBAF22}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D4CCE010-CCD1-40B9-955D-0CF97DEBAF22}.Debug|Win32.ActiveCfg = Debug|Win32
{D4CCE010-CCD1-40B9-955D-0CF97DEBAF22}.Debug|Win32.Build.0 = Debug|Win32
{D4CCE010-CCD1-40B9-955D-0CF97DEBAF22}.Release|Win32.ActiveCfg = Release|Win32
{D4CCE010-CCD1-40B9-955D-0CF97DEBAF22}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
205 changes: 205 additions & 0 deletions mak.vs2005/gzio.vcproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="gzio"
ProjectGUID="{D4CCE010-CCD1-40B9-955D-0CF97DEBAF22}"
RootNamespace="gzio"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../src"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;GZIO_EXPORTS;LUA_BUILD_AS_DLL;LUA_LIB;_CRT_SECURE_NO_WARNINGS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="zlib1d.lib lua51.lib"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../src"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;GZIO_EXPORTS;LUA_BUILD_AS_DLL;LUA_LIB;_CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="zlib1.lib lua51.lib"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\src\lgziolib.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath="..\src\lgziolib.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
4 changes: 2 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ echo:

# DO NOT DELETE

lgziolib.o: lgziolib.c
test.o: test.c
lgziolib.o: lgziolib.c lgziolib.h
test.o: test.c lgziolib.h

# (end of Makefile)
34 changes: 25 additions & 9 deletions src/lgziolib.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* gzip file I/O library
*
* Copyright (C) 2007 Judge Maygarden
*
* This file was created by Judge Maygarden (jmaygarden at computer dot org)
* through trivial changes to the "liolib.c" file from Lua 5.1.2. It was
* inspired by a post from David Burgess on the official Lua mailing list
Expand Down Expand Up @@ -36,10 +38,7 @@
#include <string.h>
#include <zlib.h>

#define lgziolib_c
#define LUA_LIB

#include "lua.h"
#include "lgziolib.h"

#include "lauxlib.h"
#include "lualib.h"
Expand Down Expand Up @@ -321,14 +320,14 @@ static int read_line (lua_State *L, gzFile f) {


static int read_chars (lua_State *L, gzFile f, size_t n) {
size_t rlen; /* how much to read */
size_t nr; /* number of chars actually read */
unsigned rlen; /* how much to read */
int nr; /* number of chars actually read */
luaL_Buffer b;
luaL_buffinit(L, &b);
rlen = LUAL_BUFFERSIZE; /* try to read that much each time */
do {
char *p = luaL_prepbuffer(&b);
if (rlen > n) rlen = n; /* cannot read more than asked */
if (rlen > n) rlen = (unsigned) n; /* cannot read more than asked */
nr = gzread(f, p, rlen);
luaL_addsize(&b, nr);
n -= nr; /* still have to read `n' chars */
Expand Down Expand Up @@ -434,7 +433,7 @@ static int g_write (lua_State *L, gzFile f, int arg) {
else {
size_t l;
const char *s = luaL_checklstring(L, arg, &l);
status = status && (gzwrite(f, s, l) == l);
status = status && (gzwrite(f, s, (unsigned) l) == l);
}
}
return pushresult(L, status, NULL);
Expand Down Expand Up @@ -539,27 +538,44 @@ static void createstdfile (lua_State *L, gzFile f, int k, const char *fname) {
}


LUALIB_API int luaopen_gzio (lua_State *L) {
GZIO_API int luaopen_gzio (lua_State *L) {
createmeta(L);

/* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */
lua_createtable(L, 2, 1);
lua_replace(L, LUA_ENVIRONINDEX);

/* open library */
luaL_register(L, LUA_GZIOLIBNAME, iolib);

/* add module metadata */
lua_pushliteral (L, "_COPYRIGHT");
lua_pushliteral (L, "Copyright (C) 2007 Judge Maygarden");
lua_settable (L, -3);
lua_pushliteral (L, "_DESCRIPTION");
lua_pushliteral (L, "Lua gzip file I/O module");
lua_settable (L, -3);
lua_pushliteral (L, "_VERSION");
lua_pushliteral (L, "gzio 0.9.0");
lua_settable (L, -3);

/* create (and set) default files */
createstdfile(L, stdin, IO_INPUT, "stdin");
createstdfile(L, stdout, IO_OUTPUT, "stdout");
createstdfile(L, stderr, 0, "stderr");

/* create environment for 'popen' */
lua_getfield(L, -1, "popen");
lua_createtable(L, 0, 1);
lua_pushcfunction(L, io_pclose);
lua_setfield(L, -2, "__close");
lua_setfenv(L, -2);
lua_pop(L, 1); /* pop 'popen' */

/* set default close function */
lua_pushcfunction(L, io_fclose);
lua_setfield(L, LUA_ENVIRONINDEX, "__close");

return 1;
}

22 changes: 22 additions & 0 deletions src/lgziolib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* gzio - Lua gzip file I/O module
*
* Author: Judge Maygarden
* Copyright (c) 2007 Judge Maygarden
*
*/

#ifndef LGZIOLIB_H
#define LGZIOLIB_H

#include "lua.h"

#ifndef GZIO_API
#define GZIO_API LUA_API
#endif /* GZIO_API */

#define LUA_GZIOLIBNAME "gzio"
GZIO_API int luaopen_gzio (lua_State *L);

#endif /* LGZIOLIB_H */

0 comments on commit ec4899f

Please sign in to comment.