plua 0.1.0

Lua preprocessor inspired by Nelua
Documentation
--- PLUA HEADER ---
local __output_lines = {}

function Plua.emit(line)
	if line then
		table.insert(__output_lines, line)
	end
end

function Plua.is_array(val)
	if type(val) ~= "table" then
		return false
	end
	local count = 0
	for _, v in pairs(val) do
		if type(v) ~= "number" then
			return false
		else
			count = count + 1
		end
	end
	for i = 1, count do
		if not val[i] and type(val[i]) ~= "nil" then
			return false
		end
	end
	return true
end

function Plua.format_value(val)
	local t = type(val)
	if t == "string" then
		return '"' .. val .. '"'
	elseif t == "table" then
		local fields = {}
		if Plua.is_array(val) then
			fields = val
		else
			for k, v in pairs(val) do
				table.insert(fields, k .. "=" .. Plua.format_value(v))
			end
		end
		return "{" .. table.concat(fields, ",") .. "}"
	elseif t == "function" or t == "thread" or t == "userdata" then
		error("Cannot interpolate value of type " .. t)
	else
		return tostring(val)
	end
end
--- PLUA METAPROGRAM ---
function class(name, base)
	Plua.emit("  local ")
	Plua.emit(name)
	Plua.emit(" = {}\r\n  function ")
	Plua.emit(name)
	Plua.emit(":new(...)\r\n    self.__index = self\r\n    setmetatable(self, { __index = ")
	Plua.emit(base or "self")
	Plua.emit(" })\r\n    ")
	if base then
		Plua.emit("      ")
		Plua.emit(name)
		Plua.emit(".super = ")
		Plua.emit(base)
		Plua.emit("\r\n    ")
	end

	Plua.emit(
		'    local obj = {}\r\n    setmetatable(obj, self)\r\n    if type(obj.init) == "function" then\r\n      obj:init(...)\r\n    end\r\n    return obj\r\n  end\r\n'
	)
end

Plua.emit("\r\n")
class("Person")

Plua.emit(
	'\r\nfunction Person:init(name, age)\r\n  self.name = name\r\n  self.age = age\r\nend\r\n\r\nfunction Person:greet()\r\n  print("Hello, I am " .. self.name .. ", and I am " .. self.age .. " years old.")\r\nend\r\n\r\n'
)
class("Corey", "Person")

Plua.emit(
	'\r\nfunction Corey:init()\r\n  Corey.super.init(self, "Corey", 33)\r\nend\r\n\r\nlocal p = Corey:new()\r\np:greet()\r\n'
) --- PLUA FOOTER ---
return table.concat(__output_lines)