Skip to content

duckafire/LIM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Last release License

LUA version Tic80 API

General vision

Lua Library Compactor is a small terminal program, created for to easily the compaction of Lua libraries in a format nicknamed of Local Package.

  In summary, Lim create a copy of the file used like argument and accomplish a serie of abbreviations and remotions of characters, trying not break the code logic. Its objective is not become the code more fast, but yes minor in relation to the characters size (and as a consequence in bytes)

  Lim can be used in practically all type of program that use Lua, but its main finality is assist in the build of small libraries to the Tic80 Tiny Computer, like the libraries natives of the project TinyLibrary.

  For obtain more informations about Lim, in relation to the rules, good pratices and others informations, click here.

Useful links
    LUA

    • Site
    • GitHub
    Tic80

    • API
    • Site
    • GitHub

Example

Original

--[[
		Simple example
]]

local seed = math.random(math.random(0, 65536))
_G.__CUR_MAP = 0 -- CURrent MAP

local function LIB_collision(ent1, ent2) -- ENTity
	-- reference
	local errorMsg = "Table not specified. Argument #"

	-- check arguments type
	assert(type(ent1) == "table", "1"..errorMsg)
	assert(type(ent2) == "table", "2"..errorMsg)

	-- collision between squares/rectangles
	return math.max(ent1.x, ent2.x) < math.min(ent1.x + ent1.width,  ent2.x + ent2.width ) &&
		   math.max(ent1.y, ent2.y) < math.min(ent1.y + ent1.height, ent2.y + ent2.height)
end

Compacted

local LIB={}
do local MR19,A0,T21,MM12,MM14=math.random,assert,type,math.max,math.min local seed=MR19(MR19(0,65536))__CUR_MAP=0 LIB.collision=function(a,b)local c="Table not specified. Argument #" A0(T21(a)=="table","1"..c)A0(T21(b)=="table","2"..c)return MM12(a.x,b.x)<MM14(a.x+a.width,b.x+b.width)&&MM12(a.y,b.y)<MM14(a.y+a.height,b.y+b.height)end end
--local reference=LIB

Local package

Structure
~    +--> Table that will be store the library functions
~    |
~ +---------+
1 local TL={}
~
2 do local MA0=math.abs TL.abs=function(a) return MA0(a) end end
~ ++ +----------------+ +----------------------------------+ +-+
~  |    |                                           |         |
~  |    +--> References to LUA functions            |         |
~  |                                                |         |
~  |                     Function of the library <--+         |
~  +----------------------------------------------------------+
~                 |
3 local lib=TL    +--> Contention to the library environment
~ +----------+
~      |
~      +--> Reference to the library