All Projects → mihacooper → luacc

mihacooper / luacc

Licence: MIT license
Lua Code Combine

Programming Languages

lua
6591 projects
shell
77523 projects

Projects that are alternatives of or similar to luacc

Vkbind
Single file Vulkan API loader.
Stars: ✭ 110 (+205.56%)
Mutual labels:  binding, loader
Glbind
Single file OpenGL API loader.
Stars: ✭ 23 (-36.11%)
Mutual labels:  binding, loader
Luarocks
LuaRocks is the package manager for the Lua programming language.
Stars: ✭ 2,324 (+6355.56%)
Mutual labels:  luajit, lua-modules
Mgs Machinery
Unity plugin for binding machinery joint in scene.
Stars: ✭ 164 (+355.56%)
Mutual labels:  binding, loader
tree-sitter.el
An Emacs dynamic module exposing tree-sitter.
Stars: ✭ 59 (+63.89%)
Mutual labels:  binding
Nimterop
Nimterop is a Nim package that aims to make C/C++ interop seamless
Stars: ✭ 244 (+577.78%)
Mutual labels:  binding
Emacs Module Rs
Rust binding and tools for emacs-module (Emacs's dynamic module support)
Stars: ✭ 203 (+463.89%)
Mutual labels:  binding
Raylib Cs
C# bindings for raylib, a simple and easy-to-use library to learn videogames programming
Stars: ✭ 182 (+405.56%)
Mutual labels:  binding
necktie
Necktie – a simple DOM binding tool
Stars: ✭ 43 (+19.44%)
Mutual labels:  binding
jsvm
Embeddable JavaScript Virtual Machine interface for Android, powered by Duktape.
Stars: ✭ 18 (-50%)
Mutual labels:  binding
nginx-lua
Nginx 1.19+ with LUA support based on Alpine Linux, Amazon Linux, Debian, Fedora and Ubuntu.
Stars: ✭ 112 (+211.11%)
Mutual labels:  luajit
Kaguya
C++ binding to Lua
Stars: ✭ 247 (+586.11%)
Mutual labels:  binding
PathOfBuildingAPI
API for Path of Building's build sharing format for builds in Path of Exile.
Stars: ✭ 25 (-30.56%)
Mutual labels:  building
Rxdatasources
UITableView and UICollectionView Data Sources for RxSwift (sections, animated updates, editing ...)
Stars: ✭ 2,784 (+7633.33%)
Mutual labels:  binding
vkel
Simple Dynamic Vulkan Extension Loader
Stars: ✭ 39 (+8.33%)
Mutual labels:  loader
Cairocffi
CFFI-based cairo bindings for Python.
Stars: ✭ 186 (+416.67%)
Mutual labels:  binding
nativejsx-loader
Webpack loader for nativejsx. 💛
Stars: ✭ 15 (-58.33%)
Mutual labels:  loader
sizeof-loader
Webpack loader that works like url-loader (or file-loader) but with extracted information such as image dimensions and file-size.
Stars: ✭ 20 (-44.44%)
Mutual labels:  loader
Preservely
Lightweight Android lib preserving objects instances during orientation changes
Stars: ✭ 22 (-38.89%)
Mutual labels:  loader
tinycoffee
tiny coffee is a framework to develop simple 2d games with opengl 3
Stars: ✭ 61 (+69.44%)
Mutual labels:  luajit

LuaCC - Lua Code Combiner

LuaCC is a command line tool that allows you combine multiple Lua files into single one without any changes of your source code. It's available on luarocks.

How it works?

LuaCC principle is based on Lua package.loaders (or package.searchers) approach. LuaCC obtain the main file of the application and any number of additional Lua modules. The main file is used as a base of result script (it's content is copied as is) and content of each additional Lua module is saved to result script as a function to special table with a key equals to the name of module.

After that the content of the modules embedded into the the table is loading using a special internal loader function. Internal loader replaces the default package.loaders[2] which actually searches for *.lua modules using pathes from package.path. By default internal loader does not completely delete package.loaders[2], firstly internal loader tries to find out the required module among the embedded modules and if it was not found internal loader will call the standard package.loaders[2] to load the module from filesystem.

Usage

luacc -o <output> [-i <include>] [-p <position>] <main> [modules] ...
  • output - output filename
    Example: luacc ... -o /path/to/result.lua
  • position
    • By default LuaCC insert generated code at the very beginning of result file but if first line of main file is starting with #! LuaCC leave it first
    • 0..N - number of main file's line after which LuaCC should place the generated code
      Example: luacc ... -p 10
    • "..." - string value determines the position of generated code
      Example: luacc ... -p "LuaCC code block"
      Note: LuaCC will looking for "--LuaCC code block" comment in main file and will replace it with generated code
      Note: LuaCC searches till first match, LuaCC matches only the whole string
  • <main> - the main file of application which will copied to result file 'as is'
    Example: luacc ... path.to.main.file
    Note: main file should always be first positional argument
    Note: use a Lua module path notation to specify this parameter
  • <modules> - additional modules which should be available with require("...") function call
    Example: luacc ... path.to.main.file path.to.module1 path.to.module2 ...
    Note: use a Lua module path notation to specify this parameter
    Note: the specified name should be the same as you use in your require("") functions
  • include - additional search paths for main file and modules
    Example: luacc ... -i /one/path/to/folder/with/modules -i /another/path/to/folder/with/modules Note: LuaCC uses includes in the same way as package.path. Firstly it tries to find out the module using the current path, then if it's not found LuaCC searches the module using each include path in specified order, as if package.path contained /the/include/path/?.lua;/the/include/path/?/init.lua.

Example

Let's show you example of project consists of main file main.lua and 2 modules: module1.lua and module2.lua

/path/to/project
    |
    |-main.lua
    |-subfolder
        |
        |-module1.lua
/path/to/external/modules
    |
    |-module2.lua

Below you can see the source code of these files:
main.lua

print "Main module"

local module1 = require "subfolder.module1"
local module2 = require "module2"

print("Module says:", module1.name)
print("Module says:", module2.name)

module1.lua

print "Module1 was loaded"
return { name = "My name is Module1" }

module2.lua

print "Module2 was loaded"
return { name = "My name is Module2" }

To combine the files use the command below:

$ lua luacc.lua -o myapp.lua -i /path/to/project -i /path/to/external/modules main subfolder.module1 module2 

And now just execute the result script:

$ lua myapp.lua
Main module
Module1 was loaded
Module2 was loaded
Module says: My name is Module1
Module says: My name is Module2

Limitations

Generally, LuaCC does not use global variables and does not affect the logic of your application, but considering the fact that LuaCC override stadard package.loaders you should be careful to override it in your application.

LuaCC works with Lua 5.1 and Lua 5.2 and I think it can work with a older versions, but it can be a problem if you'r using obsolete Lua module (old version) function.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].