lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 12/12/2013 07:09 AM, Luiz Henrique de Figueiredo wrote:
> A tiny package for amalgamated compilation of Lua 5.2 is now available at
> 	http://www.lua.org/extras/5.2/one.tar.gz
>
> It includes three files: Makefile, README, and one.c, which was mentioned
> here recently.
>
> [snip]
>
> All feedback welcome. Enjoy.
> --lhf

Threw together and attached a quick-and-dirty script to process one.c &
the Lua sources into a SQLite-style "all source in a single big chunk"
file. Perhaps useful when you need to embed the Lua source in your own
project?
-- makeone.lua
--------------
-- pre-pre-process one.c[1] to create a SQLite-style
-- all-in-one amalgramation of the Lua source
-- [1]: http://www.lua.org/extras/5.2/one.c
----------------------------------
-- released into the public domain

-- tweak these paths to fit

-- location of Lua source code to include
src="lua-5.2.3/src/"

-- location of one.c
inFile="one.c"

-- output file
outFile=io.open("lua-5.2.3.one.c", "w")

lf="\n"

-- only include any given file once
included = {}

function readFile(name)
	if included[name] then
		return
	end
	included[name] = true
	print(name)
	
	local file = io.open(name, "r")
	
	for line in file:lines() do
		local incFile = line:match [[#include%s*"(.-)"]]
		
		if incFile then
			readFile(src .. incFile)
		else
			outFile:write(line, lf)
		end
	end

	file:close()
end

readFile(inFile)