1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2007-2008 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea at videolan tod org>
8 * Pierre d'Herbemont <pdherbemont # videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
36 #include <vlc_common.h>
37 #include <vlc_plugin.h>
41 #include <lua.h> /* Low level lua C API */
42 #include <lauxlib.h> /* Higher level C API */
47 /*****************************************************************************
48 * String transformations
49 *****************************************************************************/
50 static int vlclua_decode_uri( lua_State *L )
52 int i_top = lua_gettop( L );
54 for( i = 1; i <= i_top; i++ )
56 const char *psz_cstring = luaL_checkstring( L, 1 );
57 char *psz_string = strdup( psz_cstring );
58 lua_remove( L, 1 ); /* remove elements to prevent being limited by
59 * the stack's size (this function will work with
60 * up to (stack size - 1) arguments */
61 decode_URI( psz_string );
62 lua_pushstring( L, psz_string );
68 static int vlclua_encode_uri_component( lua_State *L )
70 int i_top = lua_gettop( L );
72 for( i = 1; i <= i_top; i++ )
74 const char *psz_cstring = luaL_checkstring( L, 1 );
75 char *psz_string = encode_URI_component( psz_cstring );
77 lua_pushstring( L, psz_string );
83 static int vlclua_resolve_xml_special_chars( lua_State *L )
85 int i_top = lua_gettop( L );
87 for( i = 1; i <= i_top; i++ )
89 const char *psz_cstring = luaL_checkstring( L, 1 );
90 char *psz_string = strdup( psz_cstring );
91 lua_remove( L, 1 ); /* remove elements to prevent being limited by
92 * the stack's size (this function will work with
93 * up to (stack size - 1) arguments */
94 resolve_xml_special_chars( psz_string );
95 lua_pushstring( L, psz_string );
101 static int vlclua_convert_xml_special_chars( lua_State *L )
103 int i_top = lua_gettop( L );
105 for( i = 1; i <= i_top; i++ )
107 char *psz_string = convert_xml_special_chars( luaL_checkstring(L,1) );
109 lua_pushstring( L, psz_string );
115 /*****************************************************************************
117 *****************************************************************************/
118 static const luaL_Reg vlclua_strings_reg[] = {
119 { "decode_uri", vlclua_decode_uri },
120 { "encode_uri_component", vlclua_encode_uri_component },
121 { "resolve_xml_special_chars", vlclua_resolve_xml_special_chars },
122 { "convert_xml_special_chars", vlclua_convert_xml_special_chars },
126 void luaopen_strings( lua_State *L )
129 luaL_register( L, NULL, vlclua_strings_reg );
130 lua_setfield( L, -2, "strings" );