io

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: BSD-3-Clause Imports: 5 Imported by: 0

README

Wrappers for golang io

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 ReaderFuncTable

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

func WriterFuncTable

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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