~ubuntu-branches/ubuntu/vivid/liferea/vivid-proposed

« back to all changes in this revision

Viewing changes to src/scripting/lua.c

  • Committer: Package Import Robot
  • Author(s): bojo42
  • Date: 2012-03-29 14:17:21 UTC
  • mfrom: (1.3.9) (3.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20120329141721-tbfopcrc5797wxt7
Tags: 1.8.3-0.1ubuntu1
* New upstream release (LP: #290666, #371754, #741543, #716688)
* Merge from Debian unstable (LP: #935147), remaining changes:
* debian/patches:
  - drop gtk-status-icon.patch & notification-append as in upstream
  - drop fix_systray_behavior as mostly upstreamed and rest seems unused
  - 01_ubuntu_feedlists: update & rename, move planets to "Open Source"  
  - add_X-Ubuntu-Gettext-Domain: rebase
  - libunity.patch: rebase, apply before indicator patch (liferea_shell.c)
  - libindicate_increase_version.patch: exclude from libindicate.patch
  - deactivate libindicate.patch, seems partly upstreamed and needs rework
* debian/control: libindicate-dev, libindicate-gtk-dev & libunity-dev
* debian/liferea.indicate & liferea.install: ship indicator desktop file
* debian/rules: enable libindicate

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * @file script.c LUA scripting plugin implementation
3
 
 *
4
 
 * Copyright (C) 2006-2008 Lars Lindner <lars.lindner@gmail.com>
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
9
 
 * (at your option) any later version. 
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 
 */
20
 
 
21
 
#include <lua.h>
22
 
#include <lauxlib.h>
23
 
#include <lualib.h>
24
 
#include "liferea_wrap.h"
25
 
#include "plugin.h"
26
 
#include "script.h"
27
 
 
28
 
static lua_State *luaVM = NULL;
29
 
 
30
 
static void
31
 
lua_init (void)
32
 
{
33
 
        int i;
34
 
 
35
 
        luaVM = lua_open ();
36
 
        
37
 
        luaL_openlibs (luaVM);  /* LUA 5.1 allows loading all default modules */
38
 
        
39
 
        luaL_reg lualibs[] = {
40
 
                /* This loads swig generated Liferea module... */
41
 
                {SWIG_name,     SWIG_init},
42
 
                {NULL,          NULL}
43
 
        };
44
 
        
45
 
        for (i=0; lualibs[i].func != 0 ; i++) {
46
 
                lua_pushcfunction (luaVM, lualibs[i].func);
47
 
                lua_pushstring (luaVM, lualibs[i].name);
48
 
                lua_call (luaVM, 1, 0);
49
 
        }
50
 
}
51
 
 
52
 
static void
53
 
lua_run_cmd (const gchar *cmd)
54
 
{
55
 
        int     result;
56
 
 
57
 
        lua_getglobal(luaVM, "liferea");
58
 
        lua_pushnil(luaVM);
59
 
        lua_setfield(luaVM, -2, "calling_hook");
60
 
        lua_pop(luaVM, 1);
61
 
 
62
 
        result = luaL_dostring (luaVM, cmd);
63
 
 
64
 
        if (0 != result)
65
 
                g_warning ("Error code %d when running LUA command \"%s\"!", result, cmd);
66
 
}
67
 
 
68
 
static void
69
 
lua_run_script (const gchar *filename, const gchar *for_hook)
70
 
{
71
 
        int     result;
72
 
 
73
 
        lua_getglobal(luaVM, "liferea");
74
 
        if (for_hook != NULL)
75
 
        {
76
 
                lua_pushstring(luaVM, for_hook);
77
 
        }
78
 
        else
79
 
        {
80
 
                lua_pushnil(luaVM);
81
 
        }
82
 
        lua_setfield(luaVM, -2, "calling_hook");
83
 
        lua_pop(luaVM, 1);
84
 
 
85
 
        result = luaL_dofile (luaVM, filename);
86
 
 
87
 
        if (0 != result)
88
 
                g_warning ("Error code %d when running LUA script \"%s\"!", result, filename);
89
 
}
90
 
 
91
 
static void
92
 
lua_deinit (void)
93
 
{
94
 
        lua_close (luaVM);
95
 
}
96
 
 
97
 
static struct scriptSupportImpl ssi = {
98
 
        SCRIPT_SUPPORT_API_VERSION,
99
 
        "LUA",
100
 
        lua_init,
101
 
        lua_deinit,
102
 
        lua_run_cmd,
103
 
        lua_run_script,
104
 
};
105
 
 
106
 
static struct plugin pi = {
107
 
        PLUGIN_API_VERSION,
108
 
        "LUA Scripting Support Plugin",
109
 
        PLUGIN_TYPE_SCRIPT_SUPPORT,
110
 
        &ssi
111
 
};
112
 
 
113
 
DECLARE_PLUGIN(pi);
114
 
DECLARE_SCRIPT_SUPPORT_IMPL(ssi);