summaryrefslogtreecommitdiff
path: root/www/elinks/patches/patch-ab
blob: 3b8cd3cace40a169a715ad706ff55f384b408e13 (plain)
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
$NetBSD: patch-ab,v 1.5 2006/09/06 15:14:34 abs Exp $

--- src/scripting/lua/core.c.orig	2006-01-29 13:10:39.000000000 +0000
+++ src/scripting/lua/core.c
@@ -633,7 +633,7 @@ do_hooks_file(LS, unsigned char *prefix,
 	if (file_can_read(file)) {
 		int oldtop = lua_gettop(S);
 
-		if (lua_dofile(S, file) != 0)
+		if (luaL_dofile(S, file) != 0)
 			sleep(3); /* Let some time to see error messages. */
 		lua_settop(S, oldtop);
 	}
@@ -644,13 +644,24 @@ do_hooks_file(LS, unsigned char *prefix,
 void
 init_lua(struct module *module)
 {
-	L = lua_open();
-
-	luaopen_base(L);
-	luaopen_table(L);
-	luaopen_io(L);
-	luaopen_string(L);
-	luaopen_math(L);
+	static const luaL_Reg lualibs[] = {
+		{"", luaopen_base},
+		{LUA_TABLIBNAME, luaopen_table},
+		{LUA_IOLIBNAME, luaopen_io},
+		{LUA_OSLIBNAME, luaopen_os},
+		{LUA_STRLIBNAME, luaopen_string},
+		{LUA_MATHLIBNAME, luaopen_math},
+		{NULL, NULL}
+	};
+	const luaL_Reg *lib = lualibs;
+  
+  	L = lua_open();
+  
+	for (; lib->func; lib++) {
+		lua_pushcfunction(L, lib->func);
+		lua_pushstring(L, lib->name);
+		lua_call(L, 1, 0);
+	}
 
 	lua_register(L, LUA_ALERT, l_alert);
 	lua_register(L, "current_url", l_current_url);
@@ -755,7 +766,7 @@ handle_ret_eval(struct session *ses)
 		int oldtop = lua_gettop(L);
 
 		if (prepare_lua(ses) == 0) {
-			lua_dostring(L, expr);
+			luaL_dostring(L, expr);
 			lua_settop(L, oldtop);
 			finish_lua();
 		}