Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/editors/fxite/files/patch-src_macro.cpp
16461 views
1
--- src/macro.cpp.orig 2013-10-03 09:22:51 UTC
2
+++ src/macro.cpp
3
@@ -47,7 +47,7 @@ MacroRunner::~MacroRunner()
4
/* Catch and report script errors */
5
static FXint traceback(lua_State *L)
6
{
7
- lua_getfield(L, LUA_GLOBALSINDEX, "debug");
8
+ lua_getglobal(L, "debug");
9
if (!lua_istable(L, -1)) {
10
lua_pop(L, 1);
11
return 1;
12
@@ -324,7 +324,7 @@ static void debug_hook(lua_State *L, lua_Debug *ar)
13
/* Override a builtin Lua function, or add a new one if it doesn't exist */
14
static void override(lua_State *L, const char*module, const char* funcname, lua_CFunction newfunc)
15
{
16
- lua_getfield(L,LUA_GLOBALSINDEX,module);
17
+ lua_getglobal(L,module);
18
if (lua_istable(L,-1)) {
19
lua_pushstring(L,funcname);
20
if (newfunc) {
21
@@ -342,7 +342,7 @@ static void override(lua_State *L, const char*module,
22
/* Don't let scripts try to read from stdin, as this would block indefinitely */
23
static void close_stdin(lua_State *L)
24
{
25
- lua_getfield(L, LUA_GLOBALSINDEX, "io");
26
+ lua_getglobal(L, "io");
27
if (!lua_istable(L, -1)) {
28
lua_pop(L, 1);
29
return;
30
@@ -384,7 +384,7 @@ typedef struct {
31
32
void MacroRunner::ClearKeepers()
33
{
34
- for (FXint i=keepers.first(); i<=keepers.last(); i=keepers.next(i)) {
35
+ if (UsedSlotsInDict(&keepers)>0) for (FXint i=0; i<TotalSlotsInDict(&keepers); ++i) {
36
PersistRecord*pr=(PersistRecord*)keepers.data(i);
37
if (pr) {
38
if (pr->t==LUA_TSTRING) {
39
@@ -406,11 +406,12 @@ void MacroRunner::PushKeepers(lua_State *L)
40
lua_pushstring(L,PERSIST_TABLE_NAME);
41
lua_newtable(L);
42
lua_settable(L, -3);
43
- for (FXint i=keepers.first(); i<=keepers.last(); i=keepers.next(i)) {
44
+ if (UsedSlotsInDict(&keepers)>0) for (FXint i=0; i<TotalSlotsInDict(&keepers); ++i) {
45
PersistRecord*pr=(PersistRecord*)keepers.data(i);
46
+ if (!pr) { continue; }
47
lua_getglobal(L, LUA_MODULE_NAME);
48
lua_getfield(L,-1,PERSIST_TABLE_NAME);
49
- lua_pushstring(L,keepers.key(i));
50
+ lua_pushstring(L,DictKeyName(keepers,i));
51
switch (pr->t) {
52
case LUA_TNUMBER: { lua_pushnumber(L, pr->n); break;}
53
case LUA_TBOOLEAN:{ lua_pushboolean(L, pr->b); break;}
54
@@ -455,7 +456,7 @@ void MacroRunner::PopKeepers(lua_State *L)
55
}
56
}
57
if (pr) {
58
- keepers.replace(lua_tostring(L,-2), pr);
59
+ ReplaceInDict(&keepers,lua_tostring(L,-2),pr);
60
}
61
}
62
lua_pop(L, 1);
63
@@ -479,6 +480,9 @@ bool MacroRunner::RunMacro(const FXString &source, boo
64
lua_State *L=luaL_newstate();
65
luaL_openlibs(L);
66
luaopen_dialog(L);
67
+#if LUA_VERSION_NUM>=502
68
+ lua_setglobal(L, "dialog");
69
+#endif
70
override(L,"os","exit", osexit);
71
override(L,"io","stdin", NULL);
72
override(L,"_G","print", print);
73
@@ -487,11 +491,27 @@ bool MacroRunner::RunMacro(const FXString &source, boo
74
si->script=isfilename?source.text():NULL;
75
states.append(si);
76
lua_sethook(L,debug_hook,LUA_MASKLINE,1);
77
- luaL_register(L, LUA_MODULE_NAME, LuaFuncs());
78
- luaL_register(L, LUA_MODULE_NAME, LuaFxUtils(TopWinPub::instance(), EXE_NAME));
79
+#if LUA_VERSION_NUM<502
80
+ luaL_Register(L, LUA_MODULE_NAME, LuaFuncs());
81
+ luaL_Register(L, LUA_MODULE_NAME, LuaFxUtils(TopWinPub::instance(), EXE_NAME));
82
+ luaL_Register(L, LUA_MODULE_NAME, LuaCommands(TopWinPub::instance()));
83
+#else
84
+ int n=0;
85
+ const luaL_Reg*p;
86
+ const luaL_Reg*funcs = LuaFuncs();
87
+ const luaL_Reg*utils = LuaFxUtils(TopWinPub::instance(), EXE_NAME);
88
+ const luaL_Reg*cmds = LuaCommands(TopWinPub::instance());
89
+ for (p=funcs; p->name; p++) { n++; }
90
+ for (p=utils; p->name; p++) { n++; }
91
+ for (p=cmds; p->name; p++) { n++; }
92
+ lua_createtable(L, 0, n);
93
+ luaL_setfuncs(L, funcs, 0);
94
+ luaL_setfuncs(L, utils, 0);
95
+ luaL_setfuncs(L, cmds, 0);
96
+ lua_setglobal(L, LUA_MODULE_NAME);
97
+#endif
98
override(L,LUA_MODULE_NAME,"script", scriptname);
99
override(L,LUA_MODULE_NAME,"optimize", optimize);
100
- luaL_openlib(L, LUA_MODULE_NAME, LuaCommands(TopWinPub::instance()), 0);
101
set_string_token(L, "_VERSION", VERSION);
102
PushKeepers(L);
103
if (isfilename) {
104
105