Documentation
¶
Overview ¶
Package strings implements golang package strings functionality for lua.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
Contains lua strings.contains(string, cutset) Port of go string.Contains() returns bool
Example ¶
strings.contains(string, substring)
state := lua.NewState()
Preload(state)
source := `
local strings = require("strings")
local result = strings.contains("abcd", "d")
print(result)
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
Output: true
func HasPrefix ¶
HasPrefix lua strings.has_prefix(string, suffix): port of go string.HasPrefix() return bool
Example ¶
strings.has_prefix(string, prefix)
state := lua.NewState()
Preload(state)
source := `
local strings = require("strings")
local result = strings.has_prefix("abcd", "a")
print(result)
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
Output: true
func HasSuffix ¶
HasSuffix lua strings.has_suffix(string, prefix): port of go string.HasSuffix() returns bool
Example ¶
strings.has_suffix(string, suffix)
state := lua.NewState()
Preload(state)
source := `
local strings = require("strings")
local result = strings.has_suffix("abcd", "d")
print(result)
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
Output: true
func Preload ¶
Preload adds strings to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:
local strings = require("strings")
func Split ¶
Split lua strings.split(string, sep): port of go string.Split() returns table
Example ¶
strings.split(string, sep)
state := lua.NewState()
Preload(state)
inspect.Preload(state)
source := `
local inspect = require("inspect")
local strings = require("strings")
local result = strings.split("a b c d", " ")
print(inspect(result, {newline="", indent=""}))
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
Output: { "a", "b", "c", "d" }
func Trim ¶
Trim lua strings.trim(string, cutset) Port of go string.Trim() returns string
Example ¶
strings.trim(string, cutset)
state := lua.NewState()
Preload(state)
source := `
local strings = require("strings")
local result = strings.trim("abcd", "d")
print(result)
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
Output: abc
func TrimPrefix ¶
TrimPrefix lua strings.trim_prefix(string, cutset) Port of go string.TrimPrefix() returns string
Example ¶
strings.trim_prefix(string, cutset)
state := lua.NewState()
Preload(state)
source := `
local strings = require("strings")
local result = strings.trim_prefix("abcd", "d")
print(result)
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
Output: abcd
func TrimSuffix ¶
TrimSuffix lua strings.trim_suffix(string, cutset) Port of go string.TrimSuffix() returns string
Example ¶
strings.trim_suffix(string, cutset)
state := lua.NewState()
Preload(state)
source := `
local strings = require("strings")
local result = strings.trim_suffix("abcd", "d")
print(result)
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
Output: abc
Types ¶
This section is empty.