Commit ba2e3c57 authored by Antoine Cellerier's avatar Antoine Cellerier

Add new functions to Lua API.

Add misc.mwait(), var.create() and strings.encode_uri_component()
functions to VLC's Lua API.
parent db9ea591
......@@ -198,6 +198,13 @@ static int vlclua_mdate( lua_State *L )
return 1;
}
static int vlclua_mwait( lua_State *L )
{
double f = luaL_checknumber( L, 1 );
mwait( (int64_t)f );
return 0;
}
static int vlclua_intf_should_die( lua_State *L )
{
intf_thread_t *p_intf = (intf_thread_t*)vlclua_get_this( L );
......@@ -221,6 +228,7 @@ static const luaL_Reg vlclua_misc_reg[] = {
{ "datadir_list", vlclua_datadir_list },
{ "mdate", vlclua_mdate },
{ "mwait", vlclua_mwait },
{ "lock_and_wait", vlclua_lock_and_wait },
{ "signal", vlclua_signal },
......
......@@ -66,6 +66,21 @@ static int vlclua_decode_uri( lua_State *L )
return i_top;
}
static int vlclua_encode_uri_component( lua_State *L )
{
int i_top = lua_gettop( L );
int i;
for( i = 1; i <= i_top; i++ )
{
const char *psz_cstring = luaL_checkstring( L, 1 );
char *psz_string = encode_URI_component( psz_cstring );
lua_remove( L,1 );
lua_pushstring( L, psz_string );
free( psz_string );
}
return i_top;
}
static int vlclua_resolve_xml_special_chars( lua_State *L )
{
int i_top = lua_gettop( L );
......@@ -103,6 +118,7 @@ static int vlclua_convert_xml_special_chars( lua_State *L )
*****************************************************************************/
static const luaL_Reg vlclua_strings_reg[] = {
{ "decode_uri", vlclua_decode_uri },
{ "encode_uri_component", vlclua_encode_uri_component },
{ "resolve_xml_special_chars", vlclua_resolve_xml_special_chars },
{ "convert_xml_special_chars", vlclua_convert_xml_special_chars },
{ NULL, NULL }
......
......@@ -142,7 +142,8 @@ static int vlclua_var_get( lua_State *L )
vlc_object_t **pp_obj = luaL_checkudata( L, 1, "vlc_object" );
const char *psz_var = luaL_checkstring( L, 2 );
i_type = var_Type( *pp_obj, psz_var );
var_Get( *pp_obj, psz_var, &val );
if( var_Get( *pp_obj, psz_var, &val ) != VLC_SUCCESS )
return 0;
lua_pop( L, 2 );
return vlclua_pushvalue( L, i_type, val );
}
......@@ -161,6 +162,34 @@ static int vlclua_var_set( lua_State *L )
return vlclua_push_ret( L, i_ret );
}
static int vlclua_var_create( lua_State *L )
{
vlc_object_t **pp_obj = luaL_checkudata( L, 1, "vlc_object" );
const char *psz_var = luaL_checkstring( L, 2 );
int i_type;
switch( lua_type( L, 3 ) )
{
case LUA_TNUMBER:
i_type = VLC_VAR_FLOAT;
break;
case LUA_TBOOLEAN:
i_type = VLC_VAR_BOOL;
break;
case LUA_TSTRING:
i_type = VLC_VAR_STRING;
break;
default:
return 0;
}
int i_ret = var_Create( *pp_obj, psz_var, i_type );
if( i_ret != VLC_SUCCESS )
return vlclua_push_ret( L, i_ret );
vlc_value_t val;
vlclua_tovalue( L, i_type, &val );
return vlclua_push_ret( L, var_Set( *pp_obj, psz_var, val ) );
}
static int vlclua_var_get_list( lua_State *L )
{
vlc_value_t val;
......@@ -207,7 +236,8 @@ static int vlclua_libvlc_command( lua_State *L )
psz_cmd = luaL_checkstring( L, 1 );
val_arg.psz_string = strdup( luaL_optstring( L, 2, "" ) );
lua_pop( L, 2 );
if( !var_Type( p_this->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
int i_type = var_Type( p_this->p_libvlc, psz_cmd );
if( ! i_type & VLC_VAR_ISCOMMAND )
{
free( val_arg.psz_string );
return luaL_error( L, "libvlc's \"%s\" is not a command",
......@@ -492,6 +522,7 @@ static const luaL_Reg vlclua_var_reg[] = {
{ "get", vlclua_var_get },
{ "get_list", vlclua_var_get_list },
{ "set", vlclua_var_set },
{ "create", vlclua_var_create },
{ "add_callback", vlclua_add_callback },
{ "del_callback", vlclua_del_callback },
{ "command", vlclua_command },
......
......@@ -78,6 +78,9 @@ static lua_State * vlclua_meta_init( vlc_object_t *p_this, input_item_t * p_item
luaopen_msg( L );
luaopen_stream( L );
luaopen_strings( L );
luaopen_variables( L );
luaopen_object( L );
luaopen_misc( L );
lua_pushlightuserdata( L, p_this );
lua_setfield( L, -2, "private" );
......
......@@ -98,6 +98,7 @@ misc.cachedir(): Get the user's VLC cache directory.
misc.datadir_list( name ): FIXME: write description ... or ditch function if it isn't usefull anymore, we have datadir and userdatadir :)
misc.mdate(): Get the current date (in milliseconds).
misc.mwait(): Wait for the given date (in milliseconds).
misc.lock_and_wait(): Lock our object thread and wait for a wake up signal.
misc.signal(): Wake up our object thread.
......@@ -267,6 +268,8 @@ Strings
-------
strings.decode_uri( [uri1, [uri2, [...]]] ): Decode a list of URIs. This
function returns as many variables as it had arguments.
strings.encode_uri_component( [uri1, [uri2, [...]]] ): Encode a list of URI
components. This function returns as many variables as it had arguments.
strings.resolve_xml_special_chars( [str1, [str2, [...]]] ): Resolve XML
special characters in a list of strings. This function returns as many
variables as it had arguments.
......@@ -279,6 +282,8 @@ var.get( object, name ): Get the object's variable "name"'s value.
var.set( object, name, value ): Set the object's variable "name" to "value".
var.get_list( object, name ): Get the object's variable "name"'s value list.
1st return value is the value list, 2nd return value is the text list.
var.create( object, name, value ): Create and set the object's variable "name"
to "value". Created vars can be of type float, string or bool.
var.add_callback( object, name, function, data ): Add a callback to the
object's "name" variable. Callback functions take 4 arguments: the
......
......@@ -8,4 +8,5 @@ Examples: See googleimage.lua .
VLC Lua meta modules should define one of the following functions:
* fetch_art(): returns a path to an artwork for the given item
Available VLC specific Lua modules: msg, stream and strings. See lua/README.txt
Available VLC specific Lua modules: msg, stream, strings, variables,
objects and misc. See lua/README.txt
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment