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>
46 /*****************************************************************************
47 * Internal lua<->vlc utils
48 *****************************************************************************/
49 static void vlclua_set_object( lua_State *L, void *id, void *value )
51 lua_pushlightuserdata( L, id );
52 lua_pushlightuserdata( L, value );
53 lua_rawset( L, LUA_REGISTRYINDEX );
56 static void *vlclua_get_object( lua_State *L, void *id )
58 lua_pushlightuserdata( L, id );
59 lua_rawget( L, LUA_REGISTRYINDEX );
60 const void *p = lua_topointer( L, -1 );
65 #undef vlclua_set_this
66 void vlclua_set_this( lua_State *L, vlc_object_t *p_this )
68 vlclua_set_object( L, vlclua_set_this, p_this );
71 vlc_object_t * vlclua_get_this( lua_State *L )
73 return vlclua_get_object( L, vlclua_set_this );
76 void vlclua_set_intf( lua_State *L, intf_sys_t *p_intf )
78 vlclua_set_object( L, vlclua_set_intf, p_intf );
81 /*****************************************************************************
82 * VLC error code translation
83 *****************************************************************************/
84 int vlclua_push_ret( lua_State *L, int i_error )
86 lua_pushnumber( L, i_error );
87 lua_pushstring( L, vlc_error( i_error ) );
91 /*****************************************************************************
92 * Get the VLC version string
93 *****************************************************************************/
94 static int vlclua_version( lua_State *L )
96 lua_pushstring( L, VERSION_MESSAGE );
100 /*****************************************************************************
101 * Get the VLC copyright
102 *****************************************************************************/
103 static int vlclua_copyright( lua_State *L )
105 lua_pushliteral( L, COPYRIGHT_MESSAGE );
109 /*****************************************************************************
110 * Get the VLC license msg/disclaimer
111 *****************************************************************************/
112 static int vlclua_license( lua_State *L )
114 lua_pushstring( L, LICENSE_MSG );
118 /*****************************************************************************
120 *****************************************************************************/
121 static int vlclua_quit( lua_State *L )
123 vlc_object_t *p_this = vlclua_get_this( L );
124 /* The rc.c code also stops the playlist ... not sure if this is needed
126 libvlc_Quit( p_this->p_libvlc );
130 static int vlclua_mdate( lua_State *L )
132 lua_pushnumber( L, mdate() );
136 static int vlclua_mwait( lua_State *L )
138 double f = luaL_checknumber( L, 1 );
143 static int vlclua_action_id( lua_State *L )
145 vlc_action_t i_key = vlc_GetActionId( luaL_checkstring( L, 1 ) );
148 lua_pushnumber( L, i_key );
152 /*****************************************************************************
154 *****************************************************************************/
155 static const luaL_Reg vlclua_misc_reg[] = {
156 { "version", vlclua_version },
157 { "copyright", vlclua_copyright },
158 { "license", vlclua_license },
160 { "action_id", vlclua_action_id },
162 { "mdate", vlclua_mdate },
163 { "mwait", vlclua_mwait },
165 { "quit", vlclua_quit },
170 void luaopen_misc( lua_State *L )
173 luaL_register( L, NULL, vlclua_misc_reg );
174 lua_setfield( L, -2, "misc" );