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>
9 * RĂ©mi Duraffort <ivoire # videolan tod org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
37 #include <vlc_common.h>
38 #include <vlc_plugin.h>
40 #include <vlc_interface.h>
47 /*****************************************************************************
48 * Internal lua<->vlc utils
49 *****************************************************************************/
50 void vlclua_set_object( lua_State *L, void *id, void *value )
52 lua_pushlightuserdata( L, id );
53 lua_pushlightuserdata( L, value );
54 lua_rawset( L, LUA_REGISTRYINDEX );
57 void *vlclua_get_object( lua_State *L, void *id )
59 lua_pushlightuserdata( L, id );
60 lua_rawget( L, LUA_REGISTRYINDEX );
61 const void *p = lua_topointer( L, -1 );
66 #undef vlclua_set_this
67 void vlclua_set_this( lua_State *L, vlc_object_t *p_this )
69 vlclua_set_object( L, vlclua_set_this, p_this );
72 vlc_object_t * vlclua_get_this( lua_State *L )
74 return vlclua_get_object( L, vlclua_set_this );
77 /*****************************************************************************
78 * VLC error code translation
79 *****************************************************************************/
80 int vlclua_push_ret( lua_State *L, int i_error )
82 lua_pushnumber( L, i_error );
83 lua_pushstring( L, vlc_error( i_error ) );
87 /*****************************************************************************
88 * Get the VLC version string
89 *****************************************************************************/
90 static int vlclua_version( lua_State *L )
92 lua_pushstring( L, VERSION_MESSAGE );
96 /*****************************************************************************
97 * Get the VLC copyright
98 *****************************************************************************/
99 static int vlclua_copyright( lua_State *L )
101 lua_pushliteral( L, COPYRIGHT_MESSAGE );
105 /*****************************************************************************
106 * Get the VLC license msg/disclaimer
107 *****************************************************************************/
108 static int vlclua_license( lua_State *L )
110 lua_pushstring( L, LICENSE_MSG );
114 /*****************************************************************************
116 *****************************************************************************/
117 static int vlclua_quit( lua_State *L )
119 vlc_object_t *p_this = vlclua_get_this( L );
120 /* The rc.c code also stops the playlist ... not sure if this is needed
122 libvlc_Quit( p_this->p_libvlc );
126 static int vlclua_mdate( lua_State *L )
128 lua_pushnumber( L, mdate() );
132 static int vlclua_mwait( lua_State *L )
134 double f = luaL_checknumber( L, 1 );
139 static int vlclua_action_id( lua_State *L )
141 vlc_action_t i_key = vlc_GetActionId( luaL_checkstring( L, 1 ) );
144 lua_pushnumber( L, i_key );
148 /*****************************************************************************
150 *****************************************************************************/
151 static const luaL_Reg vlclua_misc_reg[] = {
152 { "version", vlclua_version },
153 { "copyright", vlclua_copyright },
154 { "license", vlclua_license },
156 { "action_id", vlclua_action_id },
158 { "mdate", vlclua_mdate },
159 { "mwait", vlclua_mwait },
161 { "quit", vlclua_quit },
166 void luaopen_misc( lua_State *L )
169 luaL_register( L, NULL, vlclua_misc_reg );
170 lua_setfield( L, -2, "misc" );