Esempio n. 1
0
//Func: Serialiser:Close()
//Retn: --
int JPLua_Serialiser_Close( lua_State *L ) {
	jplua_serialiser_t *serialiser = JPLua_CheckSerialiser( L, 1 );

	if ( serialiser->write ) {
		const char *buffer = cJSON_Serialize( serialiser->outRoot, 1 );

		trap->FS_Write( buffer, strlen( buffer ), serialiser->fileHandle );
		free( (void *)buffer );

		cJSON_Delete( serialiser->outRoot );
		serialiser->outRoot = NULL;
		serialiser->write = qfalse;
	}

	if ( serialiser->read ) {
		serialiser->inRoot = NULL;
		serialiser->read = qfalse;
	}

	trap->FS_Close( serialiser->fileHandle );
	serialiser->fileHandle = NULL_FILE;
	serialiser->fileName[0] = '\0';

	return 0;
}
Esempio n. 2
0
//Func: GetTable('string')
//Retn: table
int JPLua_Serialiser_GetTable( lua_State *L )
{
	jplua_serialiser_t *serialiser = JPLua_CheckSerialiser( L, 1 );
	const char *tableName = NULL;
	luaL_argcheck( L, lua_type( L, 2 ) == LUA_TSTRING, 2, "'string' expected" );
	
	tableName = lua_tostring( L, 2 );
	JPLua_Serialiser_IterateTableRead( serialiser->inRoot, tableName, L );

	return 0;
}
Esempio n. 3
0
//Func: AddTable( string, table )
//Retn: --
int JPLua_Serialiser_AddTable( lua_State *L )
{
	jplua_serialiser_t *serialiser = JPLua_CheckSerialiser( L, 1 );
	const char *tableName = NULL;
	luaL_argcheck( L, lua_type( L, 2 ) == LUA_TSTRING, 2, "'string' expected" );
	luaL_argcheck( L, lua_type( L, 3 ) == LUA_TTABLE, 3, "'table' expected" );
	
	tableName = lua_tostring( L, 2 );
	JPLua_Serialiser_IterateTableWrite( serialiser->outRoot, tableName, L );

	return 0;
}
Esempio n. 4
0
//Func: Serialiser:Close()
//Retn: --
int JPLua_Serialiser_Close( lua_State *L )
{
	jplua_serialiser_t *serialiser = JPLua_CheckSerialiser( L, 1 );
	const char *buffer = cJSON_Serialize( serialiser->outRoot, 1 );

	trap->FS_Write( buffer, strlen( buffer ), serialiser->fileHandle );
	trap->FS_Close( serialiser->fileHandle );
	serialiser->fileHandle = 0;

	free( (void *)buffer );
	cJSON_Delete( serialiser->outRoot );
	serialiser->fileName[0] = '\0';

	return 0;
}
Esempio n. 5
0
//Func: GetTable( string name )
//Retn: table
int JPLua_Serialiser_GetTable( lua_State *L ) {
	jplua_serialiser_t *serialiser = JPLua_CheckSerialiser( L, 1 );

	if ( lua_type( L, 2 ) != LUA_TSTRING ) {
		JPLua_Serialiser_Close( L );
		luaL_argcheck( L, 1, 2, "'string' expected" );
	}

	if ( !serialiser->read ) {
		Com_Printf( "Serialiser is not available to read table\n" );
		return 0;
	}

	JPLua_Serialiser_IterateTableRead( serialiser->inRoot, lua_tostring( L, 2 ), L );

	return 1;
}
Esempio n. 6
0
//Func: AddTable( string name, table )
//Retn: --
int JPLua_Serialiser_AddTable( lua_State *L ) {
	jplua_serialiser_t *serialiser = JPLua_CheckSerialiser( L, 1 );

	if ( lua_type( L, 2 ) != LUA_TSTRING ) {
		JPLua_Serialiser_Close( L );
		luaL_argcheck( L, 1, 2, "'string' expected" );
	}
	if ( lua_type( L, 3 ) != LUA_TTABLE ) {
		JPLua_Serialiser_Close( L );
		luaL_argcheck( L, 1, 3, "'table' expected" );
	}

	if ( !serialiser->write ) {
		Com_Printf( "Serialiser is not available to write table\n" );
		return 0;
	}

	JPLua_Serialiser_IterateTableWrite( serialiser->outRoot, lua_tostring( L, 2 ), L );

	return 0;
}
Esempio n. 7
0
//Func: tostring( Serialiser )
//Retn: string representing the Serialiser instance (for debug/error messages)
static int JPLua_Serialiser_ToString( lua_State *L ) {
	jplua_serialiser_t *serialiser = JPLua_CheckSerialiser( L, 1 );
	lua_pushfstring( L, "Serialiser(%s)", serialiser->fileName );
	return 1;
}