File: glspi.h

package info (click to toggle)
geany-plugins 0.19-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 6,864 kB
  • ctags: 3,059
  • sloc: ansic: 30,059; sh: 10,145; makefile: 531; python: 523
file content (133 lines) | stat: -rw-r--r-- 3,382 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

/*
 * glspi.h - Lua scripting plugin for the Geany IDE
 * See the file "geanylua.c" for copyright information.
 *
 */


#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <string.h>
#include <ctype.h>

#include "geany.h"
#include "plugindata.h"

#include "prefs.h"
#include "project.h"
#include "support.h"
#include "document.h"
#include "filetypes.h"
#include "keybindings.h"
#include "ui_utils.h"
#include "editor.h"
#include "templates.h"

#include "geanyfunctions.h"
#define main_widgets	geany->main_widgets

#include "glspi_ver.h"

#define tokenWordChars  "wordchars"
#define tokenRectSel "rectsel"
#define tokenBanner "banner"
#define tokenCaller "caller"
#define tokenScript "script"
#define tokenDirSep "dirsep"
#define tokenProject "project"

#define FAIL_STRING_ARG(argnum) \
	(glspi_fail_arg_type(L,__FUNCTION__,argnum,"string"))

#define FAIL_BOOL_ARG(argnum) \
	(glspi_fail_arg_type(L,__FUNCTION__,argnum,"boolean"))

#define FAIL_NUMERIC_ARG(argnum) \
	(glspi_fail_arg_type(L,__FUNCTION__,argnum,"number"))

#define FAIL_UNSIGNED_ARG(argnum) \
	(glspi_fail_arg_type(L,__FUNCTION__,argnum,"unsigned"))



#define FAIL_TABLE_ARG(argnum) \
	(glspi_fail_arg_type(L,__FUNCTION__,argnum,"table"))

#define FAIL_STR_OR_NUM_ARG(argnum) \
	(glspi_fail_arg_types(L,__FUNCTION__,argnum, "string", "number"))


#define DOC_REQUIRED \
	GeanyDocument *doc = document_get_current();\
	if (!(doc && doc->is_valid)) {return 0;}


#define SetTableValue(name,value,pusher) \
	lua_pushstring(L, name); \
	pusher(L, value); \
	lua_rawset(L,-3);

#define SetTableStr(name,value) SetTableValue(name,value,lua_pushstring)
#define SetTableBool(name,value) SetTableValue(name,value,lua_pushboolean)
#define SetTableNum(name,value) SetTableValue(name,(lua_Number)value,lua_pushnumber)

#define DEFAULT_MAX_EXEC_TIME 15


#define push_number(L,n) lua_pushnumber(L,(lua_Number)n)



extern GeanyData *glspi_geany_data;

#define geany_data glspi_geany_data

extern GeanyFunctions *glspi_geany_functions;

#define geany_functions glspi_geany_functions


#ifdef NEED_FAIL_ARG_TYPE
/* Pushes an error message onto Lua stack if script passes a wrong arg type */
static gint glspi_fail_arg_type(lua_State *L, const gchar *func, gint argnum, gchar *type)
{
	lua_pushfstring(L, _("Error in module \"%s\" at function %s():\n"
											" expected type \"%s\" for argument #%d\n"),
											LUA_MODULE_NAME, func+6, type, argnum);
	lua_error(L);
	return 0;
}
#endif


#ifdef NEED_FAIL_ARG_TYPES
/* Same as above, but for two overloaded types, eg "string" OR "number" */
static gint glspi_fail_arg_types(
		lua_State *L, const gchar *func, gint argnum, gchar *type1, gchar *type2)
{
	lua_pushfstring(L, _("Error in module \"%s\" at function %s():\n"
											" expected type \"%s\" or \"%s\" for argument #%d\n"),
											LUA_MODULE_NAME, func+6, type1, type2, argnum);
	lua_error(L);
	return 0;
}
#endif


#ifdef NEED_FAIL_ELEM_TYPE
/*Pushes an error message onto Lua stack if table contains wrong element type*/
static gint glspi_fail_elem_type(
		lua_State *L, const gchar *func, gint argnum, gint idx, gchar *type)
{
	lua_pushfstring(L, _("Error in module \"%s\" at function %s():\n"
											" invalid table in argument #%d:\n"
											" expected type \"%s\" for element #%d\n"),
											LUA_MODULE_NAME, func+6, argnum, type, idx);
	lua_error(L);
	return 0;
}
#endif