Posted 01 June 2014 - 01:26 AM
This API adds in functions for creating and loading packages.
A package is a file containing other files that can depend on other packages and run internal code.
Features:
Why would I use this?
Ever created a big project? Ever wanted to split it from 1 big file into a folder of smaller files? Ever wanted to get rid of the hassle of making an installer to download all the files neccessary for your project?
This handles all of that for you. You can easily pack an entire folder of files into a single file, and make minimal modifications to your code for it to work.
In addition, this is great if you want to add modularity to a project. For example, if your project uses a GUI API you made, normally you would have to include that API with the project. But what if you have another project that uses that same API. The user would have the API installed twice, taking up un-necessary space. With this, you can export the GUI API as a package, add it as a dependency in both projects, and voila! Both projects will work fine, and it will only be installed once. You can then create unlimited numbers of packages that all use this GUI API and not even have to worry about making sure it is in the project folder.
Finally, you don't need the API to use packages. Once you have created a package, it is completely independent.
Documentation
pack = package.create( string name )
— Create a new package object
pack:addFile( string filename, string content / string path )
— Add a file to the package
pack:addDependency( string name )
— Add a dependency to the package
pack:save( string path )
— Save the package
pack:saveExecutable( string path, string mainFile )
— Save the package in a way that it will run mainFile when it is run
pack = package.load( path )
— Get the data from a package (not recommended to use)
path = package.find( name )
— Find a package called [name] anywhere in the filesystem (returns nil if it can't find the package)
Download:
pastebin get ngTdqDMS package
A package is a file containing other files that can depend on other packages and run internal code.
Features:
- Single file packages with multiple files inside.
- Ability to run internal files from the package.
- Package dependencies (load other packages automatically no matter where they are in the filesystem and use them in the package).
pack = package.create( "MyPackage" ) -- create a package called MyPackage
pack:addFile( "test", "test.lua" ) -- add a file from the filesystem
pack:addFile( "test2", "print( \"hey\" )" ) -- add a file with custom content
pack:addDependency( "MyOtherPackage" ) -- make it load the other package
pack:addFile( "main", [[
require "MyOtherPackage.main" -- load files from other packages
require "test2" -- load internal files
print( "Done!" ) -- normal Lua
local content = package.read( "test" ) -- access the self package object
print( content )
]] )
pack:saveExecutable( "run_me", "main" ) -- create an executable package that will run "main" when it is called
pack:save( "path" ) -- save it as a normal package, for example an extension to something that won't run on it's own
Why would I use this?
Ever created a big project? Ever wanted to split it from 1 big file into a folder of smaller files? Ever wanted to get rid of the hassle of making an installer to download all the files neccessary for your project?
This handles all of that for you. You can easily pack an entire folder of files into a single file, and make minimal modifications to your code for it to work.
In addition, this is great if you want to add modularity to a project. For example, if your project uses a GUI API you made, normally you would have to include that API with the project. But what if you have another project that uses that same API. The user would have the API installed twice, taking up un-necessary space. With this, you can export the GUI API as a package, add it as a dependency in both projects, and voila! Both projects will work fine, and it will only be installed once. You can then create unlimited numbers of packages that all use this GUI API and not even have to worry about making sure it is in the project folder.
Finally, you don't need the API to use packages. Once you have created a package, it is completely independent.
Documentation
Spoiler
— Create a new package object
pack:addFile( string filename, string content / string path )
— Add a file to the package
pack:addDependency( string name )
— Add a dependency to the package
pack:save( string path )
— Save the package
pack:saveExecutable( string path, string mainFile )
— Save the package in a way that it will run mainFile when it is run
pack = package.load( path )
— Get the data from a package (not recommended to use)
path = package.find( name )
— Find a package called [name] anywhere in the filesystem (returns nil if it can't find the package)
Download:
pastebin get ngTdqDMS package
Edited on 01 June 2014 - 02:26 PM