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 *****************************************************************************/
40 #include <vlc_common.h>
41 #include <vlc_plugin.h>
43 #include <vlc_interface.h>
44 #include <vlc_actions.h>
45 #include <vlc_interrupt.h>
52 /*****************************************************************************
53 * Internal lua<->vlc utils
54 *****************************************************************************/
55 void vlclua_set_object( lua_State
*L
, void *id
, void *value
)
57 lua_pushlightuserdata( L
, id
);
58 lua_pushlightuserdata( L
, value
);
59 lua_rawset( L
, LUA_REGISTRYINDEX
);
62 void *vlclua_get_object( lua_State
*L
, void *id
)
64 lua_pushlightuserdata( L
, id
);
65 lua_rawget( L
, LUA_REGISTRYINDEX
);
66 const void *p
= lua_topointer( L
, -1 );
71 #undef vlclua_set_this
72 void vlclua_set_this( lua_State
*L
, vlc_object_t
*p_this
)
74 vlclua_set_object( L
, vlclua_set_this
, p_this
);
77 vlc_object_t
* vlclua_get_this( lua_State
*L
)
79 return vlclua_get_object( L
, vlclua_set_this
);
82 /*****************************************************************************
83 * VLC error code translation
84 *****************************************************************************/
85 int vlclua_push_ret( lua_State
*L
, int i_error
)
87 lua_pushnumber( L
, i_error
);
88 lua_pushstring( L
, vlc_error( i_error
) );
92 /*****************************************************************************
93 * Get the VLC version string
94 *****************************************************************************/
95 static int vlclua_version( lua_State
*L
)
97 lua_pushstring( L
, VERSION_MESSAGE
);
101 /*****************************************************************************
102 * Get the VLC copyright
103 *****************************************************************************/
104 static int vlclua_copyright( lua_State
*L
)
106 lua_pushliteral( L
, COPYRIGHT_MESSAGE
);
110 /*****************************************************************************
111 * Get the VLC license msg/disclaimer
112 *****************************************************************************/
113 static int vlclua_license( lua_State
*L
)
115 lua_pushstring( L
, LICENSE_MSG
);
119 /*****************************************************************************
121 *****************************************************************************/
122 static int vlclua_quit( lua_State
*L
)
124 vlc_object_t
*p_this
= vlclua_get_this( L
);
125 /* The rc.c code also stops the playlist ... not sure if this is needed
127 libvlc_Quit( p_this
->obj
.libvlc
);
131 static int vlclua_mdate( lua_State
*L
)
133 lua_pushnumber( L
, vlc_tick_now() );
137 static int vlclua_mwait( lua_State
*L
)
139 double f
= luaL_checknumber( L
, 1 );
141 vlc_interrupt_t
*oint
= vlclua_set_interrupt( L
);
142 int ret
= vlc_mwait_i11e( llround(f
) );
144 vlc_interrupt_set( oint
);
146 return luaL_error( L
, "Interrupted." );
150 static int vlclua_action_id( lua_State
*L
)
152 vlc_action_id_t i_key
= vlc_actions_get_id( luaL_checkstring( L
, 1 ) );
155 lua_pushnumber( L
, i_key
);
159 /*****************************************************************************
161 *****************************************************************************/
162 static const luaL_Reg vlclua_misc_reg
[] = {
163 { "version", vlclua_version
},
164 { "copyright", vlclua_copyright
},
165 { "license", vlclua_license
},
167 { "action_id", vlclua_action_id
},
169 { "mdate", vlclua_mdate
},
170 { "mwait", vlclua_mwait
},
172 { "quit", vlclua_quit
},
177 void luaopen_misc( lua_State
*L
)
180 luaL_register( L
, NULL
, vlclua_misc_reg
);
181 lua_setfield( L
, -2, "misc" );