From 2d1df4714e2736dbde7855ddcd76b4c1de822fa5 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Mon, 23 Jan 2012 21:58:02 +1000 Subject: Added a big bunch of example lua scripts for testing the speed of lua compiling. --- .../testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk4.lua | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk4.lua (limited to 'LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk4.lua') diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk4.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk4.lua new file mode 100644 index 0000000..d97c795 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk4.lua @@ -0,0 +1,82 @@ +--[[-------------------------------------------------------------------- + + lzio.lua + Lua 5 buffered streams in Lua + This file is part of Yueliang. + + Copyright (c) 2006 Kein-Hong Man + The COPYRIGHT file describes the conditions + under which this software may be distributed. + + See the ChangeLog for more information. + +----------------------------------------------------------------------]] + +--[[-------------------------------------------------------------------- +-- Notes: +-- * this is a line-based input streamer for the MK4 lexer +-- * all EOL (end-of-line) characters are translated to "\n" +-- * if last line in a file does not have an EOL character, this +-- streamer adds one, the ambiguity is due to "*l" stripping +-- * EOF uses an empty string to simplify testing in lexer +----------------------------------------------------------------------]] + +--[[-------------------------------------------------------------------- +-- local zio_init = require("lzio.lua") +-- local z = zio_init("@") +-- local z = zio_init("") +-- z:getln() +-- * get next line from input stream +-- z.name +-- * name of the chunk, "@" or "=string" +----------------------------------------------------------------------]] + +--[[-------------------------------------------------------------------- +-- Format of z structure (ZIO) +-- z.getln -- chunk reader function, reads line-by-line +-- z.name -- name of stream +----------------------------------------------------------------------]] + +return +function(buff) +--[[-------------------------------------------------------------------- +-- initialize reader +-- * reader should return a string with an EOL character, or an empty +-- string if there is nothing else to parse +----------------------------------------------------------------------]] + local reader + local z = {} + if string.sub(buff, 1, 1) == "@" then + ---------------------------------------------------------------- + -- create a chunk reader function from a source file + ---------------------------------------------------------------- + z.name = buff + local h = io.open(string.sub(buff, 2), "r") + if not h then return nil end + reader = function() + if not h or io.type(h) == "closed file" then return nil end + local data = h:read("*l") + if not data then h:close(); return "" end + return data.."\n" + end + else + ---------------------------------------------------------------- + -- create a chunk reader function from a source string + ---------------------------------------------------------------- + z.name = "=string" + reader = function() + if not buff then return nil end + local p, q, data, eol = string.find(buff, "([^\r\n]*)(\r?\n?)") + buff = string.sub(buff, q + 1) + if data == "" and eol == "" then return "" end + return data..eol + end + end +--[[-------------------------------------------------------------------- +-- initialize input stream object +----------------------------------------------------------------------]] + if not reader then return end + z.getln = reader + return z +--[[------------------------------------------------------------------]] +end -- cgit v1.1