naev 0.12.5
nxml_lua.c File Reference

Handles the saving and writing of a nlua state to XML. More...

#include "nxml_lua.h"
#include "base64.h"
#include "log.h"
#include "mission.h"
#include "nlua.h"
#include "nlua_commodity.h"
#include "nlua_faction.h"
#include "nlua_jump.h"
#include "nlua_outfit.h"
#include "nlua_ship.h"
#include "nlua_spob.h"
#include "nlua_system.h"
#include "nlua_time.h"
#include "nlua_vec2.h"
#include "utf8.h"
Include dependency graph for nxml_lua.c:

Go to the source code of this file.

Functions

static int nxml_persistDataNode (lua_State *L, xmlTextWriterPtr writer)
 Persists the node on the top of the stack and pops it.
static int nxml_unpersistDataNode (lua_State *L, xmlNodePtr parent)
 Unpersists Lua data.
static int nxml_canWriteString (const char *buf, size_t len)
 Checks whether saving the given string (from lua_tolstring) can be saved into an XML document without blowing up.
static int nxml_saveNameAttribute (xmlTextWriterPtr writer, const char *name, size_t name_len, int keynum)
 Persists the key of a key/value pair.
static int nxml_saveData (xmlTextWriterPtr writer, const char *type, const char *name, size_t name_len, const char *value, int keynum)
 Persists Lua data.
static int nxml_saveCommodity (xmlTextWriterPtr writer, const char *name, size_t name_len, const Commodity *c, int keynum)
 Commodity-specific nxml_saveData derivative.
static Commoditynxml_loadCommodity (xmlNodePtr node)
 Reverse of nxml_saveCommodity.
static int nxml_saveJump (xmlTextWriterPtr writer, const char *name, size_t name_len, const char *start, const char *dest, int keynum)
 Jump-specific nxml_saveData derivative.
int nxml_persistLua (nlua_env env, xmlTextWriterPtr writer)
 Persists all the nxml Lua data.
int nxml_unpersistLua (nlua_env env, xmlNodePtr parent)
 Unpersists Lua data into a table named "mem".

Detailed Description

Handles the saving and writing of a nlua state to XML.

Definition in file nxml_lua.c.

Function Documentation

◆ nxml_canWriteString()

int nxml_canWriteString ( const char * buf,
size_t len )
static

Checks whether saving the given string (from lua_tolstring) can be saved into an XML document without blowing up.

Parameters
bufContents of a valid Lua string.
lenCorresponding length.
Returns
1 if OK, 0 if it won't work.

Definition at line 549 of file nxml_lua.c.

◆ nxml_loadCommodity()

Commodity * nxml_loadCommodity ( xmlNodePtr node)
static

Reverse of nxml_saveCommodity.

Definition at line 121 of file nxml_lua.c.

◆ nxml_persistDataNode()

int nxml_persistDataNode ( lua_State * L,
xmlTextWriterPtr writer )
static

Persists the node on the top of the stack and pops it.

Parameters
LLua state with node to persist on top of the stack.
writerXML Writer to use.
Returns
0 on success.

Definition at line 176 of file nxml_lua.c.

◆ nxml_persistLua()

int nxml_persistLua ( nlua_env env,
xmlTextWriterPtr writer )

Persists all the nxml Lua data.

All supported contents of the table named "mem" are saved. Functions aren't supported.

Parameters
envLua environment to save.
writerXML Writer to use.
Returns
0 on success.

Definition at line 374 of file nxml_lua.c.

◆ nxml_saveCommodity()

int nxml_saveCommodity ( xmlTextWriterPtr writer,
const char * name,
size_t name_len,
const Commodity * c,
int keynum )
static

Commodity-specific nxml_saveData derivative.

Parameters
writerXML Writer to use to persist stuff.
nameName of the data to save.
name_lenData size of name (which is an arbitrary Lua string).
cCommodity to save.
keynumWhether the "name" is a numeric key, to be marked with keynum="1" in the XML.
Returns
0 on success.

Definition at line 96 of file nxml_lua.c.

◆ nxml_saveData()

int nxml_saveData ( xmlTextWriterPtr writer,
const char * type,
const char * name,
size_t name_len,
const char * value,
int keynum )
static

Persists Lua data.

Parameters
writerXML Writer to use to persist stuff.
typeType of the data to save.
nameName of the data to save.
name_lenData size of name (which is an arbitrary Lua string).
valueValue of the data to save.
keynumWhether the key is a number (not a string) and should be read back as such.
Returns
0 on success.

Definition at line 70 of file nxml_lua.c.

◆ nxml_saveJump()

int nxml_saveJump ( xmlTextWriterPtr writer,
const char * name,
size_t name_len,
const char * start,
const char * dest,
int keynum )
static

Jump-specific nxml_saveData derivative.

Parameters
writerXML Writer to use to persist stuff.
nameName of the data to save.
name_lenData size of name (which is an arbitrary Lua string).
startSystem in which the jump is.
destJump's destination system.
keynumWhether the "name" is a numeric key, to be marked with keynum="1" in the XML.
Returns
0 on success.

Definition at line 153 of file nxml_lua.c.

◆ nxml_saveNameAttribute()

int nxml_saveNameAttribute ( xmlTextWriterPtr writer,
const char * name,
size_t name_len,
int keynum )
static

Persists the key of a key/value pair.

Parameters
writerXML Writer to use to persist stuff.
nameName of the data to save.
name_lenData size of name (which is an arbitrary Lua string).
keynumWhether the "name" is a numeric key, to be marked with keynum="1" in the XML.
Returns
0 on success.

Definition at line 43 of file nxml_lua.c.

◆ nxml_unpersistDataNode()

int nxml_unpersistDataNode ( lua_State * L,
xmlNodePtr parent )
static

Unpersists Lua data.

Parameters
LState to unpersist data into.
parentNode containing all the Lua persisted data.
Returns
0 on success.

Definition at line 400 of file nxml_lua.c.

◆ nxml_unpersistLua()

int nxml_unpersistLua ( nlua_env env,
xmlNodePtr parent )

Unpersists Lua data into a table named "mem".

Parameters
envEnvironment to unpersist data into.
parentNode containing all the Lua persisted data.
Returns
0 on success.

Definition at line 530 of file nxml_lua.c.