1
2 /*
3 * glspi.h - Lua scripting plugin for the Geany IDE
4 * See the file "geanylua.c" for copyright information.
5 *
6 */
7
8
9 #ifdef HAVE_CONFIG_H
10 # include "config.h"
11 #endif
12
13 #include <lua.h>
14 #include <lualib.h>
15 #include <lauxlib.h>
16 #include <string.h>
17 #include <ctype.h>
18
19 #include <geanyplugin.h>
20 #define main_widgets geany->main_widgets
21
22 #include "glspi_ver.h"
23
24 #define tokenWordChars "wordchars"
25 #define tokenRectSel "rectsel"
26 #define tokenBanner "banner"
27 #define tokenCaller "caller"
28 #define tokenScript "script"
29 #define tokenDirSep "dirsep"
30 #define tokenProject "project"
31
32 #define FAIL_STRING_ARG(argnum) \
33 (glspi_fail_arg_type(L,__FUNCTION__,argnum,"string"))
34
35 #define FAIL_BOOL_ARG(argnum) \
36 (glspi_fail_arg_type(L,__FUNCTION__,argnum,"boolean"))
37
38 #define FAIL_NUMERIC_ARG(argnum) \
39 (glspi_fail_arg_type(L,__FUNCTION__,argnum,"number"))
40
41 #define FAIL_UNSIGNED_ARG(argnum) \
42 (glspi_fail_arg_type(L,__FUNCTION__,argnum,"unsigned"))
43
44
45
46 #define FAIL_TABLE_ARG(argnum) \
47 (glspi_fail_arg_type(L,__FUNCTION__,argnum,"table"))
48
49 #define FAIL_STR_OR_NUM_ARG(argnum) \
50 (glspi_fail_arg_types(L,__FUNCTION__,argnum, "string", "number"))
51
52
53 #define DOC_REQUIRED \
54 GeanyDocument *doc = document_get_current();\
55 if (!(doc && doc->is_valid)) {return 0;}
56
57
58 #define SetTableValue(name,value,pusher) \
59 lua_pushstring(L, name); \
60 pusher(L, value); \
61 lua_rawset(L,-3);
62
63 #define SetTableStr(name,value) SetTableValue(name,value,lua_pushstring)
64 #define SetTableBool(name,value) SetTableValue(name,value,lua_pushboolean)
65 #define SetTableNum(name,value) SetTableValue(name,(lua_Number)value,lua_pushnumber)
66
67 #define DEFAULT_MAX_EXEC_TIME 15
68
69
70 #define push_number(L,n) lua_pushnumber(L,(lua_Number)n)
71
72
73
74 extern GeanyData *glspi_geany_data;
75
76 #define geany_data glspi_geany_data
77
78
79 #ifdef NEED_FAIL_ARG_TYPE
80 /* Pushes an error message onto Lua stack if script passes a wrong arg type */
glspi_fail_arg_type(lua_State * L,const gchar * func,gint argnum,const gchar * type)81 static gint glspi_fail_arg_type(lua_State *L, const gchar *func, gint argnum, const gchar *type)
82 {
83 lua_pushfstring(L, _("Error in module \"%s\" at function %s():\n"
84 " expected type \"%s\" for argument #%d\n"),
85 LUA_MODULE_NAME, func+6, type, argnum);
86 lua_error(L);
87 return 0;
88 }
89 #endif
90
91
92 #ifdef NEED_FAIL_ARG_TYPES
93 /* Same as above, but for two overloaded types, eg "string" OR "number" */
glspi_fail_arg_types(lua_State * L,const gchar * func,gint argnum,const gchar * type1,const gchar * type2)94 static gint glspi_fail_arg_types(
95 lua_State *L, const gchar *func, gint argnum, const gchar *type1, const gchar *type2)
96 {
97 lua_pushfstring(L, _("Error in module \"%s\" at function %s():\n"
98 " expected type \"%s\" or \"%s\" for argument #%d\n"),
99 LUA_MODULE_NAME, func+6, type1, type2, argnum);
100 lua_error(L);
101 return 0;
102 }
103 #endif
104
105
106 #ifdef NEED_FAIL_ELEM_TYPE
107 /*Pushes an error message onto Lua stack if table contains wrong element type*/
glspi_fail_elem_type(lua_State * L,const gchar * func,gint argnum,gint idx,const gchar * type)108 static gint glspi_fail_elem_type(
109 lua_State *L, const gchar *func, gint argnum, gint idx, const gchar *type)
110 {
111 lua_pushfstring(L, _("Error in module \"%s\" at function %s():\n"
112 " invalid table in argument #%d:\n"
113 " expected type \"%s\" for element #%d\n"),
114 LUA_MODULE_NAME, func+6, argnum, type, idx);
115 lua_error(L);
116 return 0;
117 }
118 #endif
119
120
121 typedef void (*GsDlgRunHook) (gboolean running, gpointer user_data);
122 typedef gint (*KeyfileAssignFunc) (lua_State *L, GKeyFile*kf);
123
124
125 /* application functions */
126 void glspi_init_app_funcs(lua_State *L, const gchar*script_dir);
127 /* basic dialog box functions */
128 void glspi_init_dlg_funcs(lua_State *L, GsDlgRunHook hook);
129 /* document functions */
130 void glspi_init_doc_funcs(lua_State *L);
131 void glspi_init_kfile_module(lua_State *L, KeyfileAssignFunc *func);
132 /* menu functions */
133 void glspi_init_mnu_funcs(lua_State *L);
134 /* editor functions */
135 void glspi_init_sci_funcs(lua_State *L);
136 /* custom dialogs module */
137 void glspi_init_gsdlg_module(lua_State *L, GsDlgRunHook hook, GtkWindow *toplevel);
138 void glspi_run_script(const gchar *script_file, gint caller, GKeyFile*proj, const gchar *script_dir);
139
140 /* Pass TRUE to create hashes, FALSE to destroy them */
141 void glspi_set_sci_cmd_hash(gboolean create);
142 void glspi_set_key_cmd_hash(gboolean create);
143
144