naev 0.12.6
nlua_file.c File Reference

Handles files. More...

#include "physfsrwops.h"
#include "nlua_file.h"
#include "nluadef.h"
#include "physfs.h"
Include dependency graph for nlua_file.c:

Go to the source code of this file.

Functions

static int fileL_gc (lua_State *L)
 Frees a file.
static int fileL_eq (lua_State *L)
 Compares two files to see if they are the same.
static int fileL_new (lua_State *L)
 Opens a new file.
static int fileL_open (lua_State *L)
 Opens a File object.
static int fileL_close (lua_State *L)
 Closes a file.
static int fileL_read (lua_State *L)
 Reads from an open file.
static int fileL_write (lua_State *L)
 Reads from an open file.
static int fileL_seek (lua_State *L)
 Seeks in an open file.
static int fileL_name (lua_State *L)
 Gets the name of a file object.
static int fileL_mode (lua_State *L)
 Gets the mode a file is currently in.
static int fileL_size (lua_State *L)
 Gets the size of a file (must be open).
static int fileL_isopen (lua_State *L)
 Checks to see if a file is open.
static int fileL_filetype (lua_State *L)
 Checks to see the filetype of a path.
static int fileL_mkdir (lua_State *L)
 Makes a directory.
static int fileL_enumerate (lua_State *L)
 Returns a list of files and subdirectories of a directory.
static int fileL_remove (lua_State *L)
 Removes a file or directory.
int nlua_loadFile (nlua_env env)
 Loads the file library.
LuaFile_tlua_tofile (lua_State *L, int ind)
 Lua bindings to interact with files.
LuaFile_tluaL_checkfile (lua_State *L, int ind)
 Gets file at index or raises error if there is no file at index.
LuaFile_tlua_pushfile (lua_State *L, LuaFile_t file)
 Pushes a file on the stack.
int lua_isfile (lua_State *L, int ind)
 Checks to see if ind is a file.

Variables

static const luaL_Reg fileL_methods []

Detailed Description

Handles files.

Definition in file nlua_file.c.

Function Documentation

◆ fileL_close()

int fileL_close ( lua_State * L)
static

Closes a file.

Lua function parameter: File file File to close. Lua return parameter: true on success.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: close

Definition at line 231 of file nlua_file.c.

◆ fileL_enumerate()

int fileL_enumerate ( lua_State * L)
static

Returns a list of files and subdirectories of a directory.

Lua function parameter: string dir Name of the directory to check. Lua return parameter: table Table containing all the names (strings) of the subdirectories and files in the directory.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: enumerate

Definition at line 439 of file nlua_file.c.

◆ fileL_eq()

int fileL_eq ( lua_State * L)
static

Compares two files to see if they are the same.

Lua function parameter: File f1 File 1 to compare. Lua function parameter: File f2 File 2 to compare. Lua return parameter: boolean true if both files are the same.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: __eq

Definition at line 163 of file nlua_file.c.

◆ fileL_filetype()

int fileL_filetype ( lua_State * L)
static

Checks to see the filetype of a path.

Lua function parameter: string path Path to check to see what type it is. Lua return parameter: string What type of file it is or nil if doesn't exist.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: filetype

Definition at line 393 of file nlua_file.c.

◆ fileL_gc()

int fileL_gc ( lua_State * L)
static

Frees a file.

Lua function parameter: File file File to free.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: __gc

Definition at line 145 of file nlua_file.c.

◆ fileL_isopen()

int fileL_isopen ( lua_State * L)
static

Checks to see if a file is open.

Lua function parameter: File file File to check to see if is open. Lua return parameter: boolean true if the file is open, false otherwise.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: isOpen

Definition at line 379 of file nlua_file.c.

◆ fileL_mkdir()

int fileL_mkdir ( lua_State * L)
static

Makes a directory.

Lua function parameter: string dir Name of the directory to make. Lua return parameter: boolean True on success.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: mkdir

Definition at line 419 of file nlua_file.c.

◆ fileL_mode()

int fileL_mode ( lua_State * L)
static

Gets the mode a file is currently in.

Lua function parameter: File file File to get mode of. Lua return parameter: string Mode of the file (either 'c', 'w', 'r', or 'a')

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: getMode

Definition at line 351 of file nlua_file.c.

◆ fileL_name()

int fileL_name ( lua_State * L)
static

Gets the name of a file object.

Lua function parameter: File file File object to get name of. Lua return parameter: string Name of the file object.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: getFilename

Definition at line 337 of file nlua_file.c.

◆ fileL_new()

int fileL_new ( lua_State * L)
static

Opens a new file.

Lua function parameter: string path Path to open. Lua return parameter: File New file object.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: new

Definition at line 179 of file nlua_file.c.

◆ fileL_open()

int fileL_open ( lua_State * L)
static

Opens a File object.

Lua function parameter: File File object to open. Lua function parameter:[opt="r"] mode Mode to open the file in (should be 'r', 'w', or 'a'). Lua return parameter: boolean true on success, false and an error string on failure.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: open

Definition at line 200 of file nlua_file.c.

◆ fileL_read()

int fileL_read ( lua_State * L)
static

Reads from an open file.

Lua function parameter: File file File to read from. Lua function parameter:[opt] number bytes Number of bytes to read or all if ommitted. Lua return parameter: string Read data. Lua return parameter: number Number of bytes actually read.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: read

Definition at line 252 of file nlua_file.c.

◆ fileL_remove()

int fileL_remove ( lua_State * L)
static

Removes a file or directory.

Lua function parameter: string path Name of the path to remove. Lua return parameter: boolean True on success.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: remove

Definition at line 465 of file nlua_file.c.

◆ fileL_seek()

int fileL_seek ( lua_State * L)
static

Seeks in an open file.

Lua function parameter: File file File to seek in. Lua function parameter: number pos Position to seek to (from start of file). Lua return parameter: boolean true on success.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: seek

Definition at line 313 of file nlua_file.c.

◆ fileL_size()

int fileL_size ( lua_State * L)
static

Gets the size of a file (must be open).

Lua function parameter: File file File to get the size of. Lua return parameter: number Size of the file.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: getSize

Definition at line 365 of file nlua_file.c.

◆ fileL_write()

int fileL_write ( lua_State * L)
static

Reads from an open file.

Lua function parameter: File file File to write to. Lua function parameter: string data Data to write. Lua function parameter:[opt] number bytes Number of bytes to write.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: write

Definition at line 282 of file nlua_file.c.

◆ lua_isfile()

int lua_isfile ( lua_State * L,
int ind )

Checks to see if ind is a file.

Parameters
LLua state to check.
indIndex position to check.
Returns
1 if ind is a file.

Definition at line 123 of file nlua_file.c.

◆ lua_pushfile()

LuaFile_t * lua_pushfile ( lua_State * L,
LuaFile_t file )

Pushes a file on the stack.

Parameters
LLua state to push file into.
fileFile to push.
Returns
Newly pushed file.

Definition at line 108 of file nlua_file.c.

◆ lua_tofile()

LuaFile_t * lua_tofile ( lua_State * L,
int ind )

Lua bindings to interact with files.

Note
The API here is designed to be compatible with that of LÖVE.

Lua module: file

Gets file at index.

Parameters
LLua state to get file from.
indIndex position to find the file.
Returns
File found at the index in the state.

Definition at line 83 of file nlua_file.c.

◆ luaL_checkfile()

LuaFile_t * luaL_checkfile ( lua_State * L,
int ind )

Gets file at index or raises error if there is no file at index.

Parameters
LLua state to get file from.
indIndex position to find file.
Returns
File found at the index in the state.

Definition at line 94 of file nlua_file.c.

◆ nlua_loadFile()

int nlua_loadFile ( nlua_env env)

Loads the file library.

Parameters
envEnvironment to load file library into.
Returns
0 on success.

Definition at line 63 of file nlua_file.c.

Variable Documentation

◆ fileL_methods

const luaL_Reg fileL_methods[]
static
Initial value:
= {
{ "__gc", fileL_gc },
{ "__eq", fileL_eq },
{ "new", fileL_new },
{ "open", fileL_open },
{ "close", fileL_close },
{ "read", fileL_read },
{ "write", fileL_write },
{ "seek", fileL_seek },
{ "getFilename", fileL_name },
{ "getMode", fileL_mode },
{ "getSize", fileL_size },
{ "isOpen", fileL_isopen },
{ "filetype", fileL_filetype },
{ "mkdir", fileL_mkdir },
{ "enumerate", fileL_enumerate },
{ "remove", fileL_remove },
{ 0, 0 } }
static int fileL_close(lua_State *L)
Closes a file.
Definition nlua_file.c:231
static int fileL_seek(lua_State *L)
Seeks in an open file.
Definition nlua_file.c:313
static int fileL_write(lua_State *L)
Reads from an open file.
Definition nlua_file.c:282
static int fileL_size(lua_State *L)
Gets the size of a file (must be open).
Definition nlua_file.c:365
static int fileL_enumerate(lua_State *L)
Returns a list of files and subdirectories of a directory.
Definition nlua_file.c:439
static int fileL_new(lua_State *L)
Opens a new file.
Definition nlua_file.c:179
static int fileL_eq(lua_State *L)
Compares two files to see if they are the same.
Definition nlua_file.c:163
static int fileL_isopen(lua_State *L)
Checks to see if a file is open.
Definition nlua_file.c:379
static int fileL_gc(lua_State *L)
Frees a file.
Definition nlua_file.c:145
static int fileL_mkdir(lua_State *L)
Makes a directory.
Definition nlua_file.c:419
static int fileL_open(lua_State *L)
Opens a File object.
Definition nlua_file.c:200
static int fileL_read(lua_State *L)
Reads from an open file.
Definition nlua_file.c:252
static int fileL_remove(lua_State *L)
Removes a file or directory.
Definition nlua_file.c:465
static int fileL_name(lua_State *L)
Gets the name of a file object.
Definition nlua_file.c:337
static int fileL_mode(lua_State *L)
Gets the mode a file is currently in.
Definition nlua_file.c:351
static int fileL_filetype(lua_State *L)
Checks to see the filetype of a path.
Definition nlua_file.c:393

File metatable methods.

Definition at line 38 of file nlua_file.c.