io

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2023 License: BSD-3-Clause Imports: 7 Imported by: 0

README

io wrappers

NOTE: These aren't exposed to LUA directly, but used as utilities for other classes, which need the bridge between lua file and these interfaces:

  • io.Reader
  • io.Writer

See usages of CheckIOReader and CheckIOWriter in json and yaml modules to treat args as the appropriate go type.

Going the other way, ReaderFuncTable and WriterFuncTable are provided for libraries that need to register a type that behaves like a io.Reader or io.Writer and may used as a file from lua. See example uses of this in the strings and base64 modules, such as this snippet from base64.

//registerBase64Encoder Registers the encoder type and its methods
func registerBase64Encoder(L *lua.LState) {
	mt := L.NewTypeMetatable(base64EncoderType)
	L.SetGlobal(base64EncoderType, mt)
	L.SetField(mt, "__index", lio.WriterFuncTable(L))
}

//registerBase64Decoder Registers the decoder type and its methods
func registerBase64Decoder(L *lua.LState) {
	mt := L.NewTypeMetatable(base64DecoderType)
	L.SetGlobal(base64DecoderType, mt)
	L.SetField(mt, "__index", lio.ReaderFuncTable(L))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckIOReader

func CheckIOReader(L *lua.LState, n int) io.Reader

CheckIOReader tries to cast to UserData and to io.Reader, otherwise it wraps and checks for "read" method

func CheckIOWriter

func CheckIOWriter(L *lua.LState, n int) io.Writer

CheckIOWriter tries to cast to UserData and to io.Writer, otherwise it wraps and checks for "write" method

func IOReaderClose

func IOReaderClose(L *lua.LState) int

func IOReaderRead

func IOReaderRead(L *lua.LState) int

func IOWriterClose

func IOWriterClose(L *lua.LState) int

func IOWriterWrite

func IOWriterWrite(L *lua.LState) int

func NewLuaIOWrapper

func NewLuaIOWrapper(L *lua.LState, io lua.LValue) *luaIOWrapper

NewLuaIOWrapper creates a new luaIOWrapper atop the lua io object

func ReadLine added in v0.7.0

func ReadLine(reader io.Reader) (string, error)

ReadLine reads a line from any reader.

func ReaderFuncTable

func ReaderFuncTable(L *lua.LState) *lua.LTable

func ToRuneReader added in v0.7.0

func ToRuneReader(reader io.Reader) io.RuneReader

ToRuneReader Converts reader to an io.RuneReader

func WriterFuncTable

func WriterFuncTable(L *lua.LState) *lua.LTable

Types

type UnbufferedRuneReader added in v0.7.0

type UnbufferedRuneReader struct {
	// contains filtered or unexported fields
}

UnbufferedRuneReader doesn't attempt to buffer the underlying reader, but does buffer enough to decode utf8 runes.

func (*UnbufferedRuneReader) ReadRune added in v0.7.0

func (u *UnbufferedRuneReader) ReadRune() (r rune, size int, err error)

ReadRune reads a single rune, and returns the rune, its byte-length, and possibly an error. see the code for fmt.Scanln - which is not public, but which does, but tokenizing on space, which is not desirable. The implementation in fmt.Scanln also implements io.RuneScanner, which is not needed here as newlines are discarded.

Jump to

Keyboard shortcuts

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