[vlc-commits] Lua: remove the timers API

Rémi Denis-Courmont git at videolan.org
Sun Mar 25 19:24:12 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Mar 25 20:22:51 2012 +0300| [cdc3063510e67cc817644dd756c23cc456251ffb] | committer: Rémi Denis-Courmont

Lua: remove the timers API

The Lua interpreter is not thread-safe. So this API made absolutely no
sense: the timer callback is called asynchronously from another thread.
Fortunately, none of our Lua scripts used this except for testing.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cdc3063510e67cc817644dd756c23cc456251ffb
---

 modules/lua/libs/misc.c |  103 -----------------------------------------------
 share/lua/README.txt    |    4 --
 share/lua/intf/test.lua |   12 -----
 3 files changed, 0 insertions(+), 119 deletions(-)

diff --git a/modules/lua/libs/misc.c b/modules/lua/libs/misc.c
index a64e227..abc05d3 100644
--- a/modules/lua/libs/misc.c
+++ b/modules/lua/libs/misc.c
@@ -178,107 +178,6 @@ static int vlclua_action_id( lua_State *L )
 }
 
 /*****************************************************************************
- * Timer functions
- *****************************************************************************/
-static int vlclua_timer_schedule( lua_State *L );
-static int vlclua_timer_getoverrun( lua_State *L);
-
-static const luaL_Reg vlclua_timer_reg[] = {
-    { "schedule",   vlclua_timer_schedule   },
-    { "getoverrun", vlclua_timer_getoverrun },
-    { NULL,         NULL                    }
-};
-
-typedef struct
-{
-    lua_State *L;
-    vlc_timer_t timer;
-    char *psz_callback;
-} vlclua_timer_t;
-
-static int vlclua_timer_schedule( lua_State *L )
-{
-    vlclua_timer_t **pp_timer = (vlclua_timer_t**)luaL_checkudata( L, 1, "timer" );
-    if( !pp_timer || !*pp_timer )
-        luaL_error( L, "Can't get pointer to timer" );
-
-    bool b_relative = luaL_checkboolean( L, 2 );
-    mtime_t i_value = luaL_checkinteger( L, 3 );
-    mtime_t i_interval = luaL_checkinteger( L, 4 );
-
-    vlc_timer_schedule( (*pp_timer)->timer, b_relative, i_value, i_interval );
-    return 0;
-}
-
-static int vlclua_timer_getoverrun( lua_State *L )
-{
-    vlclua_timer_t **pp_timer = (vlclua_timer_t**)luaL_checkudata(L, 1, "timer" );
-    if( !pp_timer || !*pp_timer )
-        luaL_error( L, "Can't get pointer to timer" );
-
-    lua_pushinteger( L, vlc_timer_getoverrun( (*pp_timer)->timer ) );
-    return 1;
-}
-
-static void vlclua_timer_callback( void *data )
-{
-    vlclua_timer_t *p_timer = (vlclua_timer_t*)data;
-    lua_State *L = p_timer->L;
-
-    lua_getglobal( L, p_timer->psz_callback );
-    if( lua_pcall( L, 0, 0, 0 ) )
-    {
-        const char *psz_err = lua_tostring( L, -1 );
-        msg_Err( vlclua_get_this( L ), "Error while running the timer callback: '%s'", psz_err );
-        lua_settop( L, 0 );
-    }
-}
-
-static int vlclua_timer_delete( lua_State *L )
-{
-    vlclua_timer_t **pp_timer = (vlclua_timer_t**)luaL_checkudata( L, 1, "timer" );
-    if( !pp_timer || !*pp_timer )
-        luaL_error( L, "Can't get pointer to timer" );
-
-    vlc_timer_destroy( (*pp_timer)->timer );
-    free( (*pp_timer)->psz_callback );
-    free( (*pp_timer) );
-    return 0;
-}
-
-static int vlclua_timer_create( lua_State *L )
-{
-    if( !lua_isstring( L, 1 ) )
-        return luaL_error( L, "timer(function_name)" );
-
-    vlclua_timer_t *p_timer = malloc( sizeof( vlclua_timer_t ) );
-    if( vlc_timer_create( &p_timer->timer, vlclua_timer_callback, p_timer ) )
-    {
-        free( p_timer );
-        return luaL_error( L, "Cannot initialize the timer" );
-    }
-
-    p_timer->L = L;
-    p_timer->psz_callback = strdup( luaL_checkstring( L, 1 ) );
-
-    vlclua_timer_t **pp_timer = lua_newuserdata( L, sizeof( vlclua_timer_t* ) );
-    *pp_timer = p_timer;
-
-    /* Create the object */
-    if( luaL_newmetatable( L, "timer" ) )
-    {
-        lua_newtable( L );
-        luaL_register( L, NULL, vlclua_timer_reg );
-        lua_setfield( L, -2, "__index" );
-        lua_pushcfunction( L, vlclua_timer_delete );
-        lua_setfield( L, -2, "__gc" );
-    }
-    lua_setmetatable( L, -2 );
-
-    return 1;
-}
-
-/*****************************************************************************
  *
  *****************************************************************************/
 static const luaL_Reg vlclua_misc_reg[] = {
@@ -296,8 +195,6 @@ static const luaL_Reg vlclua_misc_reg[] = {
     { "should_die", vlclua_intf_should_die },
     { "quit", vlclua_quit },
 
-    { "timer", vlclua_timer_create },
-
     { NULL, NULL }
 };
 
diff --git a/share/lua/README.txt b/share/lua/README.txt
index d757b76..6c3ae25 100644
--- a/share/lua/README.txt
+++ b/share/lua/README.txt
@@ -170,10 +170,6 @@ misc.lock_and_wait(): Lock our object thread and wait for a wake up signal.
 misc.should_die(): Returns true if the interface should quit.
 misc.quit(): Quit VLC.
 
-misc.timer(callback): Create a timer which call the callback function
-  :schedule(relative, value, interval): schedule the timer
-  :getoverrun(): number of time the timer got overrun (normally 0)
-
 Net
 ---
 net.url_parse( url, [option delimiter] ): Parse URL. Returns a table with
diff --git a/share/lua/intf/test.lua b/share/lua/intf/test.lua
index 54dbf9a..2e5dfd7 100644
--- a/share/lua/intf/test.lua
+++ b/share/lua/intf/test.lua
@@ -7,24 +7,12 @@ function assert_url(result, protocol, username, password, host, port, path)
     assert(result.path     == path)
 end
 
-local timer_count = 0
-function timer_callback()
-  timer_count = timer_count + 1
-end
-
 vlc.msg.info('---- Testing misc functions ----')
 vlc.msg.info('version: ' .. vlc.misc.version())
 vlc.msg.info('copyright: ' .. vlc.misc.copyright())
 vlc.msg.info('license: ' .. vlc.misc.license())
 vlc.msg.info('mdate: ' .. vlc.misc.mdate())
 
-vlc.msg.info(' * Testing the timer')
-local timer = vlc.misc.timer('timer_callback')
-timer:schedule(true, 100, 0)
-vlc.misc.mwait(vlc.misc.mdate()+1000000)
-assert(timer_count == 1)
-vlc.msg.info('   [done]')
-
 vlc.msg.info('---- Testing config functions ----')
 vlc.msg.info('datadir: ' .. vlc.config.datadir())
 vlc.msg.info('userdatadir: ' .. vlc.config.userdatadir())



More information about the vlc-commits mailing list