Finish event dispatching section.
[screen-lua.git] / src / script.c
blobe9500994140b1c75ace6778683293129eca7b13e
1 /* Copyright (c) 2008 Sadrul Habib Chowdhury (sadrul@users.sf.net)
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 3, or (at your option)
6 * any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program (see the file COPYING); if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
18 ****************************************************************
21 #include "config.h"
22 #include "screen.h"
24 struct scripts
26 struct scripts *s_next;
27 struct ScriptFuncs *fns;
30 struct scripts *scripts;
32 static void
33 AddScript(struct ScriptFuncs *sf)
35 struct scripts *ns = (struct scripts *)calloc(1, sizeof(*ns));
36 if (!ns)
37 return;
38 ns->fns = sf;
39 ns->s_next = scripts;
40 scripts = ns;
43 #define ALL_SCRIPTS(fn, params, stop) do { \
44 struct scripts *iter; \
45 for (iter = scripts; iter; iter = iter->s_next) \
46 { \
47 if (iter->fns->fn && (ret = (iter->fns->fn params)) && stop) \
48 break; \
49 } \
50 } while (0)
52 void ScriptInit(void)
54 int ret;
55 ALL_SCRIPTS(sf_Init, (), 0);
58 void ScriptFinit(void)
60 int ret;
61 ALL_SCRIPTS(sf_Finit, (), 0);
64 void ScriptForeWindowChanged(void)
66 int ret;
67 ALL_SCRIPTS(sf_ForeWindowChanged, (), 0);
70 void ScriptSource(const char *path)
72 int ret;
73 /* If one script loader accepts the file, we don't send it to any other loader */
74 ALL_SCRIPTS(sf_Source, (path), 1);
77 int ScriptProcessCaption(const char *str, struct win *win, int len)
79 int ret = 0;
80 ALL_SCRIPTS(sf_ProcessCaption, (str, win, len), 1);
81 return ret;
84 int ScriptCommandExecuted(const char *command, const char **args, int argc)
86 int ret = 0;
87 ALL_SCRIPTS(sf_CommandExecuted, (command, args, argc), 0);
88 return ret;
91 #define HAVE_LUA 1 /* XXX: Remove */
92 #if HAVE_LUA
93 extern struct ScriptFuncs LuaFuncs;
94 #endif
96 void LoadScripts(void)
98 /* XXX: We could load the script loaders dynamically */
99 #if HAVE_LUA
100 AddScript(&LuaFuncs);
101 #endif