]> git.sesse.net Git - vlc/blob - modules/misc/lua/libs/messages.c
Implement Lua objects in the C code directly. Fix most type checks. Move every thing...
[vlc] / modules / misc / 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 #include <vlc_charset.h>
40 #include <vlc_aout.h>
41
42 #include <lua.h>        /* Low level lua C API */
43 #include <lauxlib.h>    /* Higher level C API */
44 #include <lualib.h>     /* Lua libs */
45
46 #include "../vlc.h"
47 #include "../libs.h"
48
49 /*****************************************************************************
50  * Messaging facilities
51  *****************************************************************************/
52 static int vlclua_msg_dbg( lua_State *L )
53 {
54     int i_top = lua_gettop( L );
55     vlc_object_t *p_this = vlclua_get_this( L );
56     int i;
57     for( i = 1; i <= i_top; i++ )
58         msg_Dbg( p_this, "%s", luaL_checkstring( L, 1 ) );
59     return 0;
60 }
61
62 static int vlclua_msg_warn( lua_State *L )
63 {
64     int i_top = lua_gettop( L );
65     vlc_object_t *p_this = vlclua_get_this( L );
66     int i;
67     for( i = 1; i <= i_top; i++ )
68         msg_Warn( p_this, "%s", luaL_checkstring( L, i ) );
69     return 0;
70 }
71
72 static int vlclua_msg_err( lua_State *L )
73 {
74     int i_top = lua_gettop( L );
75     vlc_object_t *p_this = vlclua_get_this( L );
76     int i;
77     for( i = 1; i <= i_top; i++ )
78         msg_Err( p_this, "%s", luaL_checkstring( L, i ) );
79     return 0;
80 }
81
82 static int vlclua_msg_info( lua_State *L )
83 {
84     int i_top = lua_gettop( L );
85     vlc_object_t *p_this = vlclua_get_this( L );
86     int i;
87     for( i = 1; i <= i_top; i++ )
88         msg_Info( p_this, "%s", luaL_checkstring( L, i ) );
89     return 0;
90 }
91
92 /*****************************************************************************
93  *
94  *****************************************************************************/
95 static const luaL_Reg vlclua_msg_reg[] = {
96     { "dbg", vlclua_msg_dbg },
97     { "warn", vlclua_msg_warn },
98     { "err", vlclua_msg_err },
99     { "info", vlclua_msg_info },
100     { NULL, NULL }
101 };
102
103 void luaopen_msg( lua_State *L )
104 {
105     lua_newtable( L );
106     luaL_register( L, NULL, vlclua_msg_reg );
107     lua_setfield( L, -2, "msg" );
108 }