tac

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2023 License: BSD-3-Clause Imports: 5 Imported by: 8

README

tac GoDoc

Usage

local file = io.open("data.txt", "w")
file:write("1", "\n")
file:write("2", "\n")
file:write("3", "\n")

local tac = require("tac")
local scanner, err = tac.open("data.txt")
if err then error(err) end

while true do
    local line = scanner:line()
    if line == nil then break end
    print(line)
end
scanner:close()

-- Output:
-- 3
-- 2
-- 1

Documentation

Overview

Package tac implements file scanner (from end to up) functionality for lua.

Example

tac.open(), tac_ud:line(), tac_ud:close()

state := lua.NewState()
Preload(state)
source := `
        local file = io.open("./test/file.txt", "w")
        file:write("1", "\n")
        file:write("2", "\n")
        file:write("3", "\n")

        local tac = require("tac")
        local scanner, err = tac.open("./test/file.txt")
        if err then error(err) end

        while true do
            local line = scanner:line()
            if line == nil then break end
            print(line)
        end
        scanner:close()
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

3
2
1

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close(L *lua.LState) int

Close lua tac_ud:close() close current file for tac

func Line

func Line(L *lua.LState) int

Line lua tac_ud:line() return next upper line: string or nil

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func Open

func Open(L *lua.LState) int

Open lua tac.open(filename) open filename for tac scan returns (tac_ud, err)

func Preload

func Preload(L *lua.LState)

Preload adds tac to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:

local tac = require("tac")

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL