lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Here's my list of functions:

--[[ Tables ]]

-- move array element #from to position 'to', shifting all other elements
-- Example: table.move({1, "2 from", 3, 4, 5}, 2, 4) -> {1, 3, 4, "2 from", 5}
table.move(t, from, to)

-- shallow copy of a table, metatable is ignored
-- If overwrite is false, only values not present in 'dest' table would be copied
table.copy(src, dest = {}, overwrite = false)

-- find a value in a table, returns key
table.find(t, v0)

-- find a value in an array, returns key
table.ifind(t, v0)


--[[ Bitwise operations ]]

bit.Or
bit.And
bit.Xor

-- a and not b - unusual, but useful
bit.AndNot(a, b)


--[[ Math ]]

function math.round(val)

function math.div(v1, v2)


--[[ Default metatable for numbers ]]

tohex(self)

div(self, v2)

round(self)
floor(self)
ceil(self)


--[[ Path functions ]]

-- if 'isdir' is false, files are iterated, otherwise directories are.
-- Usage: for fileName, fileSize in path.find("c:\*.*") do
path.find(filter, isdir = false)

-- Extracts file name from full path
path.name(filePath)

-- Extracts file extension
path.ext(filePath)

-- Changes extension to 'ext'
path.setext(filePath, ext)

-- Adds trailing slash to the path
path.addslash(filePath)

path.GetCurrentDirectory()
path.SetCurrentDirectory(dir)


--[[ IO ]]

-- Saves string as a file. If translate is true, io.open is called with "t" mode.
io.SaveString(path, s, translate = false)

-- Loads file as string. If translate is true, io.open is called with "t" mode.
io.LoadString(path, translate = false)