Browse Source

Rename some files. Stop using init hook - init Lua interpreter from within the plugin_init function. Register action handler as a sym instead of as a hook. Once we have plugin_fini ready I'll remove the fini hook as well.

Stanislav Galabov 11 years ago
parent
commit
f861b3cd57

+ 1 - 0
.gitignore

@@ -1,6 +1,7 @@
 .deps
 .dirstamp
 .libs
+.*.swp
 *.o
 *.lo
 *.la

+ 0 - 16
plugins/lua/hook.h

@@ -1,16 +0,0 @@
-#ifndef _HOOK_H_
-#define _HOOK_H_
-
-#include <clish/shell.h>
-
-#include <lua.h>
-#include <lualib.h>
-#include <lauxlib.h>
-
-#define LUA_UDATA	"lua state"
-
-void l_print_error(lua_State *, const char *, const char *, int);
-
-#include "hook_spec.h"
-
-#endif /* _HOOK_H_ */

+ 0 - 8
plugins/lua/hook_spec.h

@@ -1,8 +0,0 @@
-#ifndef _HOOK_SPEC_H_
-#define _HOOK_SPEC_H
-
-CLISH_HOOK_INIT(clish_plugin_hook_init);
-CLISH_HOOK_FINI(clish_plugin_hook_fini);
-CLISH_PLUGIN_SYM(clish_plugin_hook_action);
-
-#endif /* _HOOK_SPEC_H_ */

+ 2 - 2
plugins/lua/hook_action.c → plugins/lua/lua_action.c

@@ -1,8 +1,8 @@
 #include <lub/string.h>
 
-#include "hook.h"
+#include "private.h"
 
-CLISH_PLUGIN_SYM(clish_plugin_hook_action)
+CLISH_PLUGIN_SYM(clish_plugin_lua_action)
 {
 	clish_context_t *context = (clish_context_t *) clish_context;
 	lua_State *L = clish_shell__get_udata(context->shell, LUA_UDATA);

+ 2 - 2
plugins/lua/hook_fini.c → plugins/lua/lua_fini.c

@@ -1,8 +1,8 @@
 #include <stdlib.h>
 
-#include "hook.h"
+#include "private.h"
 
-CLISH_HOOK_FINI(clish_plugin_hook_fini)
+CLISH_HOOK_FINI(clish_plugin_lua_fini)
 {
 	clish_context_t *context = (clish_context_t *) clish_context;
 	lua_State *L = clish_shell__del_udata(context->shell, LUA_UDATA);

+ 2 - 4
plugins/lua/hook_init.c → plugins/lua/lua_init.c

@@ -4,7 +4,7 @@
 
 #include <lub/string.h>
 
-#include "hook.h"
+#include "private.h"
 
 static bool_t
 load_scripts(lua_State *L, char *path)
@@ -57,10 +57,8 @@ load_scripts(lua_State *L, char *path)
 	return result;
 }
 
-CLISH_HOOK_INIT(clish_plugin_hook_init)
+int clish_plugin_init_lua(clish_shell_t *shell)
 {
-	clish_context_t *context = (clish_context_t *) clish_context;
-	clish_shell_t *shell = (clish_shell_t *) context->shell;
 	lua_State *L = NULL;
 	char *scripts_path = getenv("CLISH_SCRIPTS_PATH");
 

+ 1 - 1
plugins/lua/lua_print_error.c

@@ -1,4 +1,4 @@
-#include "hook.h"
+#include "private.h"
 
 void
 l_print_error(lua_State *L, const char *func, const char *when, int res)

+ 5 - 6
plugins/lua/module.am

@@ -2,7 +2,7 @@ lib_LTLIBRARIES			+= clish_plugin_lua.la
 clish_plugin_lua_la_SOURCES	 = 
 clish_plugin_lua_la_LIBADD	 =
 clish_plugin_lua_la_LDFLAGS	 = -avoid-version -module -shared
-clish_plugin_lua_la_LDFLAGS	+= -export-symbols-regex '^clish_plugin_.*'
+clish_plugin_lua_la_LDFLAGS	+= -export-symbols-regex "^clish_plugin_lua_"
 
 clish_plugin_lua_la_LDFLAGS	+= -L/usr/local/lib -llua-5.1
 clish_plugin_lua_la_CFLAGS	 = -I/usr/local/include/lua51
@@ -16,12 +16,11 @@ clish_plugin_lua_la_DEPENDENCIES = \
 	libclish.la
 
 nobase_include_HEADERS		+= \
-	plugins/lua/hook.h \
-	plugins/lua/hook_spec.h
+	plugins/lua/private.h
 
 clish_plugin_lua_la_SOURCES	+= \
 	plugins/lua/plugin_init.c \
-	plugins/lua/hook_init.c \
-	plugins/lua/hook_fini.c \
-	plugins/lua/hook_action.c \
+	plugins/lua/lua_init.c \
+	plugins/lua/lua_fini.c \
+	plugins/lua/lua_action.c \
 	plugins/lua/lua_print_error.c

+ 6 - 6
plugins/lua/plugin_init.c

@@ -1,13 +1,13 @@
-#include "hook.h"
+#include "private.h"
 
 CLISH_PLUGIN_INIT
 {
-	clish_plugin_add_phook(plugin, clish_plugin_hook_init, "hook_init",
-			CLISH_SYM_TYPE_INIT);
-	clish_plugin_add_phook(plugin, clish_plugin_hook_fini, "hook_fini",
+
+	clish_plugin_init_lua((clish_shell_t *)clish_shell);
+
+	clish_plugin_add_phook(plugin, clish_plugin_lua_fini, "hook_fini",
 			CLISH_SYM_TYPE_FINI);
-	clish_plugin_add_phook(plugin, clish_plugin_hook_action, "hook_action",
-			CLISH_SYM_TYPE_ACTION);
+	clish_plugin_add_sym(plugin, clish_plugin_lua_action, "hook_action");
 
 	return 0;
 }

+ 18 - 0
plugins/lua/private.h

@@ -0,0 +1,18 @@
+#ifndef _PLUGIN_H_
+#define _PLUGIN_H_
+
+#include <clish/shell.h>
+
+#include <lua.h>
+#include <lualib.h>
+#include <lauxlib.h>
+
+#define LUA_UDATA	"lua state"
+
+void l_print_error(lua_State *, const char *, const char *, int);
+int clish_plugin_init_lua(clish_shell_t *shell);
+
+CLISH_HOOK_FINI(clish_plugin_lua_fini);
+CLISH_PLUGIN_SYM(clish_plugin_lua_action);
+
+#endif /* _PLUGIN_H_ */

+ 0 - 1
xml-examples/lua/startup.xml

@@ -6,7 +6,6 @@
 
 	<PLUGIN name="lua_hooks" file="clish_plugin_lua.so"/>
 
-	<HOOK name="init" builtin="hook_init@lua_hooks"/>
 	<HOOK name="fini" builtin="hook_fini@lua_hooks"/>
 
 	<!--