Skip to content

Lua Types

Reece Hagan edited this page Nov 12, 2023 · 5 revisions

Types in this page.

Global functions

doborz(path)
--directory location that has a build.borz inside or just pointing to a lua file.

project(name, language, binType, tags)
project(name, language, binType)
--Returns the correct project for the given language with the name and binType setup.
--tags is an array of strings.
--Example:
project("MyPlugin", Language.C, BinType.SharedObj, {"plugin"})

createPkgDep(libraryPaths, libraryNames, includePaths, defines, needsRPath)
--Returns a PkgDep filled out with the given tables

isBuildConf(conf)
--Returns true if the given conf matches the current set build config.
--Example:
if isBuildConf("debug") then
   log.info("We're building a debug build.")
end

log

log.debug(message)

log.info(message)

log.warning(message)
log.warn(message)

log.error(message)

log.fatal(message)

NOTE! log.fatal will stop execution.


dir

dir.create(dir)
--Returns a bool if creation was successful.

dir.exists(dir)
--Returns a bool if directory exists.

dir.delete(dir, recursive = true)
--Recursive works like C#, you can read what that means at the bottom of this code block.

dir.listDirs(dir)
--Returns an array of dirs in the given dir

dir.listDirs()
--This is just calling listDirs but giving it the path of your scripts current directory.

dir.copy(src, dest)
--Copies a directory recursively.
--Example:
dir.copy("scripts", "bin/scripts")

dir.recursiveFixModifyTimes(dir)
--This goes through the directory and updates everything recursively to the current time.
--Useful when you extract some files from a zip and it has the wrong time.

Heres the Microsoft docs on Directory.Delete(string, bool)


file

file.delete(file)

file.exists(file)
--Returns a bool if the file exists or not.

path

path.combine(paths...)
--Concats paths together.
--Returns a single string of the combined path.
--Example: 
x = path.combine("..", "myfolder/foo", "file.txt")
-- Unix   : x = "../myfolder/foo/file.txt"
-- Windows: x = "..\myfolder\foo\file.txt" (This could be wrong, idk.)
 
path.getFileName(path)
--Returns the file name out of the path or if it failed will return nil.
--Example
x = path.getFileName("myfolder/file.txt")
-- x = "file.txt"

path.getFileNameNoExt(path)
--Pretty much like path.getFileName but no extension.
--Example
x = path.getFileNameNoExt("myfolder/file.txt")
-- x = "file"

path.getAbsolute(path)
path.getAbs(path)
--Returns the absolute path to the given input path.

ws

Workspace contains the projects and some extra settings.

ws.Name = "Workspace"
ws.Configs = {"debug", "release"}

ws.GetSortedProjectList()
--This will return an array of projects on success sorted by dependencies.

pkgconf

pkgconf.fromAko(akoFilePath)

This command does a lot, lets see a example requirements.ako file

sdl2 [
    version ">=2.20.2"
    req+
]
lol [
    name "sdl2"
]
foo [
   name "unknown-pkg"
]

If a name isn't given it will just use the key name as the pkg name, for versions you can use <=, >= and = on the left-hand side to set exactly what version you want and req aka required basically will cause the script to fail if its not found.

Lets run this.

pkgs = pkgconf.fromAko("requirements.ako")
--pkgs["foo"] is nil

foo = project("foo", Language.Cpp, BinType.ConsoleApp)
--...
foo.AddDep(pkgs["sdl2"], true)
--...

You can look at the project page here to learn about AddDep.

Now about req:

Q: What happens if I have required set and a package fails due to mismatched version or its not found?

A message will be shown to the user and borz will just exit safely

The value in the table is a PkgDep, this is different from a Project as PkgDeps can't be compiled only linked and have the common elements a pkgconfig PC file would have, you can even do your own package querying using the function

pkg = createPkgDep(libraryPaths, libraryNames, includePaths, defines, needsRPath)

If you want to just individually query for a package:

pkg = pkgconf.query(name, required = true, version)
--Like fromAko if required is set borz will quit safely else you will get nil if it couldn't be found.

util

This class is just full of random utility functions.

util.sleep(ms)
--Sleeps for the given amount of milliseconds.

util.runCmd(cmd, args)
--Runs the given cmd with the given args.
--Example:
exitCode, output, error = util.runCmd("gcc", "--version")
-- exitCode = 0
-- output   = "gcc (GCC)......"
-- error    = ""

util.downloadFile(url, outputLocation)
--This is a simple file downloader.
--Example:
success = util.downloadFile("someurl.com/file.txt", "bin/file.txt")
-- success = true or false

util.conf_add(keys, value)
--Keys is an array of strings, value is a string.
--WARNING: This is a temporary function and will be removed in the future when
--the ako config is better integrated with lua.

util.getResource(resourceType, url, extractTo)
util.getResource(resourceType, url, extractTo, fileToCheck, folderToExtract)
--Optional: fileToCheck, folderToExtract
--resourceType: Archive just for now.
--extractTo: Path to extract downloaded content to.
--fileToCheck: If the given file exists then skip.
--folderToExtract: Path in archive to copy from.
--
--This will download the given url and extract it to the given extractTo.

The example for download file is pretty big so it gets its own section.

local url = "https://glad.dav1d.de/generated/notarealid/glad.zip"
local binPath = path.getAbs("binaries")
local gladExtractPath = path.combine(binPath, "glad")
local validFile = path.combine(gladExtractPath, "src", "glad.c")

success = util.getResource(ResourceType.Archive, url, gladExtractPath, validFile)
if success then
    dir.recursiveFixModifyTimes(gladExtractPath)
end
-- success = true or false
Clone this wiki locally