]> git.sesse.net Git - vlc/blob - modules/lua/libs/messages.c
Lua: revert should_die to using vlc_object_alive()
[vlc] / modules / lua / libs / messages.c
1 /*****************************************************************************
2  * messages.c
3  *****************************************************************************
4  * Copyright (C) 2007-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea at videolan tod org>
8  *          Pierre d'Herbemont <pdherbemont # videolan.org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #ifndef  _GNU_SOURCE
29 #   define  _GNU_SOURCE
30 #endif
31
32 #ifdef HAVE_CONFIG_H
33 # include "config.h"
34 #endif
35
36 #include <vlc_common.h>
37 #include <vlc_plugin.h>
38 #include <vlc_meta.h>
39
40 #include "../vlc.h"
41 #include "../libs.h"
42
43 /*****************************************************************************
44  * Messaging facilities
45  *****************************************************************************/
46 static int vlclua_msg_dbg( lua_State *L )
47 {
48     int i_top = lua_gettop( L );
49     vlc_object_t *p_this = vlclua_get_this( L );
50     int i;
51     for( i = 1; i <= i_top; i++ )
52         msg_Dbg( p_this, "%s", luaL_checkstring( L, i ) );
53     return 0;
54 }
55
56 static int vlclua_msg_warn( lua_State *L )
57 {
58     int i_top = lua_gettop( L );
59     vlc_object_t *p_this = vlclua_get_this( L );
60     int i;
61     for( i = 1; i <= i_top; i++ )
62         msg_Warn( p_this, "%s", luaL_checkstring( L, i ) );
63     return 0;
64 }
65
66 static int vlclua_msg_err( lua_State *L )
67 {
68     int i_top = lua_gettop( L );
69     vlc_object_t *p_this = vlclua_get_this( L );
70     int i;
71     for( i = 1; i <= i_top; i++ )
72         msg_Err( p_this, "%s", luaL_checkstring( L, i ) );
73     return 0;
74 }
75
76 static int vlclua_msg_info( lua_State *L )
77 {
78     int i_top = lua_gettop( L );
79     vlc_object_t *p_this = vlclua_get_this( L );
80     int i;
81     for( i = 1; i <= i_top; i++ )
82         msg_Info( p_this, "%s", luaL_checkstring( L, i ) );
83     return 0;
84 }
85
86 /*****************************************************************************
87  *
88  *****************************************************************************/
89 static const luaL_Reg vlclua_msg_reg[] = {
90     { "dbg", vlclua_msg_dbg },
91     { "warn", vlclua_msg_warn },
92     { "err", vlclua_msg_err },
93     { "info", vlclua_msg_info },
94     { NULL, NULL }
95 };
96
97 void luaopen_msg( lua_State *L )
98 {
99     lua_newtable( L );
100     luaL_register( L, NULL, vlclua_msg_reg );
101     lua_setfield( L, -2, "msg" );
102 }