summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Wiles <keith.wiles@intel.com>2017-10-03 15:43:28 -0500
committerKeith Wiles <keith.wiles@intel.com>2017-11-25 07:48:59 -0600
commitb1316f99e07f4c2dd16d713bc9cca6ac40154913 (patch)
tree11973b425dbef44df952bd025f03e47c49a84db2
parentc513b28b2f9253624610b1eed551156d849f2eaa (diff)
downloaddpdk-draft-cli-b1316f99e07f4c2dd16d713bc9cca6ac40154913.zip
dpdk-draft-cli-b1316f99e07f4c2dd16d713bc9cca6ac40154913.tar.gz
dpdk-draft-cli-b1316f99e07f4c2dd16d713bc9cca6ac40154913.tar.xz
cli: add lua support without headers
Signed-off-by: Keith Wiles <keith.wiles@intel.com>
-rw-r--r--lib/librte_cli/cli.c36
-rw-r--r--lib/librte_cli/cli.h2
2 files changed, 19 insertions, 19 deletions
diff --git a/lib/librte_cli/cli.c b/lib/librte_cli/cli.c
index 5d54c61..f72f6e0 100644
--- a/lib/librte_cli/cli.c
+++ b/lib/librte_cli/cli.c
@@ -43,15 +43,7 @@
#include "cli.h"
#include "cli_string_fns.h"
-#ifdef RTE_LIBRTE_LUA
-#ifdef CLI_STANDALONE
-#include "lua.h"
-#include "lauxlib.h"
-#else
-#include <lua.h>
-#include <lauxlib.h>
-#endif
-#endif
+int (*lua_dofile)(void *, const char *);
RTE_DEFINE_PER_LCORE(struct cli *, cli);
@@ -532,7 +524,7 @@ cli_execute(void)
else if (p[0] == '!') { /* History command */
hist = cli_history_line(atoi(&p[1]));
if (!hist) {
- cli_printf("Invalid number %d\n", atoi(&p[1]));
+ cli_printf("Unknown history line number %d\n", atoi(&p[1]));
return 0;
}
/* History lines are already trimmed and ready to be executed */
@@ -946,6 +938,15 @@ cli_set_prompt(cli_prompt_t prompt)
}
/**
+ * set the callout function pointer to execute a lua file.
+ */
+void
+cli_set_lua_callback( int(*func)(void *, const char *))
+{
+ lua_dofile = func;
+}
+
+/**
* Load and execute a command file or Lua script file.
*
*/
@@ -958,19 +959,16 @@ cli_execute_cmdfile(const char *filename)
gb_reset_buf(this_cli->gb);
if (strstr(filename, ".lua") || strstr(filename, ".LUA") ) {
-#ifdef RTE_LIBRTE_LUA
if (!this_cli->user_state) {
cli_printf(">>> User State for CLI not set for Lua\n");
return -1;
}
- /* Execute the Lua script file. */
- if (luaL_dofile(this_cli->user_state, filename) != 0) {
- cli_printf("%s", lua_tostring(this_cli->user_state,-1));
- return -1;
- }
-#else
- cli_printf(">>> Lua is not enabled in configuration!\n");
-#endif
+ if (lua_dofile) {
+ /* Execute the Lua script file. */
+ if (lua_dofile(this_cli->user_state, filename) != 0)
+ return -1;
+ } else
+ cli_printf(">>> Lua is not enabled in configuration!\n");
} else {
FILE *fd;
char buff[256];
diff --git a/lib/librte_cli/cli.h b/lib/librte_cli/cli.h
index bf5aba1..09b9e49 100644
--- a/lib/librte_cli/cli.h
+++ b/lib/librte_cli/cli.h
@@ -1170,6 +1170,8 @@ cli_quit(void)
this_cli->quit_flag = 1;
}
+void cli_set_lua_callback( int(*func)(void *, const char *));
+
#ifdef __cplusplus
}
#endif