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>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
36 #include <vlc_common.h>
37 #include <vlc_plugin.h>
39 #include <vlc_charset.h>
41 #include <vlc_interface.h>
43 #include <lua.h> /* Low level lua C API */
44 #include <lauxlib.h> /* Higher level C API */
45 #include <lualib.h> /* Lua libs */
50 /*****************************************************************************
51 * Internal lua<->vlc utils
52 *****************************************************************************/
53 vlc_object_t * vlclua_get_this( lua_State *L )
55 vlc_object_t * p_this;
56 lua_getglobal( L, "vlc" );
57 lua_getfield( L, -1, "private" );
58 p_this = (vlc_object_t*)lua_topointer( L, lua_gettop( L ) );
63 /*****************************************************************************
64 * VLC error code translation
65 *****************************************************************************/
66 int vlclua_push_ret( lua_State *L, int i_error )
68 lua_pushnumber( L, i_error );
69 lua_pushstring( L, vlc_error( i_error ) );
73 /*****************************************************************************
74 * Get the VLC version string
75 *****************************************************************************/
76 static int vlclua_version( lua_State *L )
78 lua_pushstring( L, VLC_Version() );
82 /*****************************************************************************
83 * Get the VLC copyright
84 *****************************************************************************/
85 static int vlclua_copyright( lua_State *L )
87 lua_pushstring( L, COPYRIGHT_MESSAGE );
91 /*****************************************************************************
92 * Get the VLC license msg/disclaimer
93 *****************************************************************************/
94 static int vlclua_license( lua_State *L )
96 lua_pushstring( L, LICENSE_MSG );
100 /*****************************************************************************
102 *****************************************************************************/
103 static int vlclua_quit( lua_State *L )
105 vlc_object_t *p_this = vlclua_get_this( L );
106 /* The rc.c code also stops the playlist ... not sure if this is needed
108 vlc_object_kill( p_this->p_libvlc );
112 /*****************************************************************************
113 * Global properties getters
114 *****************************************************************************/
115 static int vlclua_datadir( lua_State *L )
117 lua_pushstring( L, config_GetDataDir() );
121 static int vlclua_userdatadir( lua_State *L )
123 lua_pushstring( L, config_GetUserDataDir() );
127 static int vlclua_homedir( lua_State *L )
129 lua_pushstring( L, config_GetHomeDir() );
133 static int vlclua_configdir( lua_State *L )
135 char *dir = config_GetUserConfDir();
136 lua_pushstring( L, dir );
141 static int vlclua_cachedir( lua_State *L )
143 char *dir = config_GetCacheDir();
144 lua_pushstring( L, dir );
149 static int vlclua_datadir_list( lua_State *L )
151 const char *psz_dirname = luaL_checkstring( L, 1 );
152 char *ppsz_dir_list[] = { NULL, NULL, NULL, NULL };
153 char **ppsz_dir = ppsz_dir_list;
156 if( vlclua_dir_list( psz_dirname, ppsz_dir_list ) != VLC_SUCCESS )
159 for( ; *ppsz_dir; ppsz_dir++ )
161 lua_pushstring( L, *ppsz_dir );
162 lua_rawseti( L, -2, i );
167 /*****************************************************************************
169 *****************************************************************************/
170 static int vlclua_lock_and_wait( lua_State *L )
172 vlc_object_t *p_this = vlclua_get_this( L );
173 int b_quit = vlc_object_lock_and_wait( p_this );
174 lua_pushboolean( L, b_quit );
178 static int vlclua_signal( lua_State *L )
180 vlc_object_t *p_this = vlclua_get_this( L );
181 vlc_object_signal( p_this );
185 static int vlclua_mdate( lua_State *L )
187 lua_pushnumber( L, mdate() );
191 static int vlclua_intf_should_die( lua_State *L )
193 intf_thread_t *p_intf = (intf_thread_t*)vlclua_get_this( L );
194 lua_pushboolean( L, intf_ShouldDie( p_intf ) );
198 /*****************************************************************************
200 *****************************************************************************/
201 static const luaL_Reg vlclua_misc_reg[] = {
202 { "version", vlclua_version },
203 { "copyright", vlclua_copyright },
204 { "license", vlclua_license },
206 { "datadir", vlclua_datadir },
207 { "userdatadir", vlclua_userdatadir },
208 { "homedir", vlclua_homedir },
209 { "configdir", vlclua_configdir },
210 { "cachedir", vlclua_cachedir },
211 { "datadir_list", vlclua_datadir_list },
213 { "mdate", vlclua_mdate },
215 { "lock_and_wait", vlclua_lock_and_wait },
216 { "signal", vlclua_signal },
218 { "should_die", vlclua_intf_should_die },
219 { "quit", vlclua_quit },
224 void luaopen_misc( lua_State *L )
227 luaL_register( L, NULL, vlclua_misc_reg );
228 lua_setfield( L, -2, "misc" );