Browse Source

Use plugin_fini; Use plugin's conf mechanism for defining the script dir instead of relying on global env vars (for the moment it's rudimentary and just uses the string provided by clish_plugin__get_conf() without doing any further parsing)

Stanislav Galabov 11 years ago
parent
commit
434a687559

+ 0 - 13
plugins/lua/lua_fini.c

@@ -1,13 +0,0 @@
-#include <stdlib.h>
-
-#include "private.h"
-
-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);
-
-	lua_close(L);
-
-	return (0);
-}

+ 3 - 8
plugins/lua/lua_init.c

@@ -6,6 +6,8 @@
 
 #include "private.h"
 
+char *scripts_path = NULL;
+
 static bool_t
 load_scripts(lua_State *L, char *path)
 {
@@ -60,13 +62,6 @@ load_scripts(lua_State *L, char *path)
 int clish_plugin_init_lua(clish_shell_t *shell)
 {
 	lua_State *L = NULL;
-	char *scripts_path = getenv("CLISH_SCRIPTS_PATH");
-
-	if (!scripts_path)
-		if(!(scripts_path = getenv("CLISH_PATH"))) {
-			printf("%s: Lua scripts dir not specified\n", __func__);
-			return (-1);
-		}
 
 	if (!(L = luaL_newstate())) {
 		printf("%s: Failed to instantiate Lua interpreter\n", __func__);
@@ -75,7 +70,7 @@ int clish_plugin_init_lua(clish_shell_t *shell)
 
 	luaL_openlibs(L);
 
-	if (!load_scripts(L, scripts_path)) {
+	if (scripts_path && !load_scripts(L, scripts_path)) {
 		return (-1);
 	}
 

+ 1 - 1
plugins/lua/module.am

@@ -20,7 +20,7 @@ nobase_include_HEADERS		+= \
 
 clish_plugin_lua_la_SOURCES	+= \
 	plugins/lua/plugin_init.c \
+	plugins/lua/plugin_fini.c \
 	plugins/lua/lua_init.c \
-	plugins/lua/lua_fini.c \
 	plugins/lua/lua_action.c \
 	plugins/lua/lua_print_error.c

+ 13 - 0
plugins/lua/plugin_fini.c

@@ -0,0 +1,13 @@
+#include <stdlib.h>
+
+#include "private.h"
+
+CLISH_PLUGIN_FINI
+{
+	lua_State *L = clish_shell__del_udata(clish_shell, LUA_UDATA);
+
+	if (L)
+		lua_close(L);
+
+	return (0);
+}

+ 6 - 2
plugins/lua/plugin_init.c

@@ -2,11 +2,15 @@
 
 CLISH_PLUGIN_INIT
 {
+	char *conf = clish_plugin__get_conf(plugin);
+
+	if (conf)
+		scripts_path = conf;
 
 	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__set_name(plugin, "lua_hooks");
+
 	clish_plugin_add_sym(plugin, clish_plugin_lua_action, "hook_action");
 
 	return 0;

+ 1 - 1
plugins/lua/private.h

@@ -9,10 +9,10 @@
 
 #define LUA_UDATA	"lua state"
 
+extern char *scripts_path;
 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_ */

+ 2 - 3
xml-examples/lua/startup.xml

@@ -4,9 +4,8 @@
  xsi:schemaLocation="http://clish.sourceforge.net/XMLSchema
                      http://clish.sourceforge.net/XMLSchema/clish.xsd">
 
-	<PLUGIN name="lua_hooks" file="clish_plugin_lua.so"/>
-
-	<HOOK name="fini" builtin="hook_fini@lua_hooks"/>
+     <PLUGIN name="lua_hooks"
+	     file="clish_plugin_lua.so">/usr2/klish-rw/xml-examples/lua</PLUGIN>
 
 	<!--
 	<STARTUP view="test-view"/>