SubCritical module

SubCritical is a normal Lua module. It can also be addressed by subcritical, SC, or sc.

result = SubCritical.ParseCommandLine(string)
Returns each token in string. Like in a shell, tokens are separated by spaces, and you can include spaces in tokens with quotes. Some form of escaping is supported as well. (I won't document the specifics.)
Example: ParseCommandLine[[foo bar "canada goo"se 'cheese\'n\'rice']] -> {"foo", "bar", "canada goose", "cheese'n'rice"}
table = SubCritical.Choices(class)
Returns an array containing the names of all available implementors of class, in order from best priority to worst. Normally you do not need this unless you want to offer the user a choice of which implementor to use (see ConstructSpecific.)
object = SubCritical.Construct(class, ...) object = assert(SubCritical.Construct(class, ...))
Returns, if possible, either an instance of class directly or an instance of a class that inherits from it. If you wish an error to be thrown on failure, it is adviseable to assert its return value (as shown above).
Constructors may both return nil or throw an error on failure, depending on the failure. If the failure was caused by malformed constructor parameters, it should throw an error.
object = SubCritical.ConstructSpecific(class, ...) object = assert(SubCritical.ConstructSpecific(class, ...))
Returns, if possible, an instance of class directly, and not a subclass. If you wish an error to be thrown on failure, it is adviseable to assert its return value (as shown above). Normally you do not need this unless you want to offer the user a choice of which implementor to use (see Choices.)
true_path = SubCritical.ConstructPath(path[, level]) true_path = SubCritical.Path(path[, level]) true_path = SCPath(path[, level]) true_path = scpath(path[, level]) true_path = P"path"
Returns a platform-specific equivalent to path. path is a UNIX-style path relative to the directory containing the source file containing the calling code. Calling ConstructPath from code not loaded directly from a file is unwise, and will have different semantics on different platforms.
If you write code that wishes to wrap ConstructPath without itself affecting where the path points to, use the level parameter. A value of 3 denotes the function calling you, 4 denotes the function that called that function, etc.
newpath = SubCritical.ConstructRelativePath(source, path) newpath = SubCritical.RelPath(sourcepath, relpath)
sourcepath is a Path object. relpath is a string containing a UNIX-style relative path. The path that results is returned as a Path object.
Null components and leading and trailing slashes in relpath are ignored. If you want to hardcode an absolute path (and break your game on other OSes) manually construct a Path object.
files = SubCritical.ListFiles(extension[, dirpath]) files = SubCritical.ListFilesRecursive(extension[, dirpath]) folders = SubCritical.ListFolders(extension[, dirpath]) folders = SubCritical.ListFoldersRecursive(extension[, dirpath])
Returns a table containing Paths for every file (or folder, depending on which function you call) ending with extension (which you may wish to prepend with a period, as in ".png", and which may be empty but not nil) in a given directory (or, by default, the directory containing the calling code). ListFilesRecursive/ListFoldersRecursive also includes files in subdirectories, but ListFoldersRecursive will not check subdirectories of folders it returns.
The files are always returned in alphabetical* order; ListFilesRecursive will return (for a given directory) first the contents of any subdirectories in alphabetical order, then the contents of this directory, also in alphabetical order.
*Rather than introduce terrible collation issues, this actually does binary lexicographical order rather than alphabetical order. For English, and some other languages, these are the same. Caveat programmer.
... = SubCritical.Util.name(...) ... = SubCritical.util.name(...) ... = SCUtil.name(...) ... = scutil.name(...)
All of the above are equivalent ways to call a native utility function named name.
file = SubCritical.Var.Read(..., name) file = SubCritical.var.Read(..., name) file = SCVar.Read(..., name) file = scvar.Read(..., name)
Returns a Lua file (actually, a table shadowing one) to read a file by the name of name (optionally under one or more subdirectories passed as additional arguments) in the SubCritical configuration directory. The location of this directory varies from platform to platform.
name, as well as any subdirectories, must not begin with a period or end with a tilde (~). In addition, if it contains slashes (/), they are converted to underscores (_). Some platforms may name the file differently than the name you provide; on those platforms, it is guaranteed that there is a one-to-one mapping between name parameters and actual filenames.
file = SubCritical.Var.Write(..., name) file = SubCritical.var.Write(..., name) file = SCVar.Write(..., name) file = scvar.Write(..., name)
Returns a Lua file (actually, a table shadowing one) to create or replace a file by the name of name (optionally under one or more subdirectories passed as additional arguments) in the SubCritical configuration directory. The location of this directory varies from platform to platform. The file is not actually created / replaced until it is explicitly closed (with :close()). In particular, if the garbage collector gets it, the file is never actually created!
See Var.Read for restrictions on name
file = SubCritical.Var.Update(..., name) file = SubCritical.var.Update(..., name) file = SCVar.Update(..., name) file = scvar.Update(..., name)
Returns a Lua file (actually, a table shadowing one) to update a file by the name of name (optionally under one or more subdirectories passed as additional arguments) in the SubCritical configuration directory. If the file does not exist, it is created. If it does, the file position starts at the end of the file. In either case, the file handle can be seeked, read from, and written to at will. The file is not actually updated until it is explicitly closed (with :close()). In particular, if the garbage collector gets it, the file is never updated!
See Var.Read for restrictions on name
path = SubCritical.Var.Path(..., name) path = SubCritical.var.Path(..., name) path = SCVar.Path(..., name) path = scvar.Path(..., name)
Returns the Path to the corresponding configuration file (optionally under one or more subdirectories passed as additional arguments). If name is nil, returns the Path to the configuration directory (or, if given, one or more subdirectories underneath it). As far as I know, the only legitimate use for this function is to load a Graphic from a config file, or list some subset of the configuration files.
See Var.Read for restrictions on name
SubCritical.Var.Remove(..., name) SubCritical.var.Remove(..., name) SCVar.Remove(..., name) scvar.Remove(..., name)
Deletes the corresponding configuration file, if it exists. Never fails, even if the file was not actually deleted. Also tries to delete any temporary copies of the file that exist. Like the other SCVar functions, one or more subdirectories can optionally be passed.
See Var.Read for restrictions on name
path = SubCritical.GetPluginPath(name)
Returns the platform-specific path of a (hopefully) user-writable directory where your game (identified by name) may expect to find user-installed plugins. The directory is created if it doesn't exist.
Best used with ListFiles or ListFilesRecursive.
See Var.Read for restrictions on name
version_string = ("%03x"):format(SubCritical.version) if(SubCritical.version < 0x0b5) then error("This game requires feature X that was added in SubCritical 0b5.") end
The SubCritical version, as a number. Interpreted as a hexadecimal number, the least significant digit is the minor release number, the next most significant the release type, and the rest is the major version. (Example: 0b5; the sixth beta release of major version 0.)
print(SubCritical.copyright)
A copyright string relevant to the current version of the SubCritical engine.

Back to index