summaryrefslogtreecommitdiff
path: root/core/src/xmake/readline
diff options
context:
space:
mode:
authorTitanSnow <[email protected]>2017-05-10 07:05:41 +0800
committerTitanSnow <[email protected]>2017-05-10 07:52:11 +0800
commitc8a1edb15828a188b2c2e2139a366aad006aaf0e (patch)
tree9f568a58f65e6846894a744d9f3e0ec9ece178ac /core/src/xmake/readline
parentd80214fcfaa2f90b2ba6ec6991329d38901cff66 (diff)
add module readline
Diffstat (limited to 'core/src/xmake/readline')
-rw-r--r--core/src/xmake/readline/prefix.h41
-rw-r--r--core/src/xmake/readline/readline.c65
2 files changed, 106 insertions, 0 deletions
diff --git a/core/src/xmake/readline/prefix.h b/core/src/xmake/readline/prefix.h
new file mode 100644
index 000000000..626cde146
--- /dev/null
+++ b/core/src/xmake/readline/prefix.h
@@ -0,0 +1,41 @@
+/*!The Make-like Build Utility based on Lua
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Copyright (C) 2015 - 2017, TBOOX Open Source Group.
+ *
+ * @author TitanSnow
+ * @file prefix.h
+ *
+ */
+#ifndef XM_READLINE_PREFIX_H
+#define XM_READLINE_PREFIX_H
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "../prefix.h"
+#ifdef XM_CONFIG_API_HAVE_READLINE
+# include <stdio.h> // on some OS (like centos) required
+# include <readline/readline.h>
+# include <readline/history.h>
+#endif
+
+
+#endif
+
+
diff --git a/core/src/xmake/readline/readline.c b/core/src/xmake/readline/readline.c
new file mode 100644
index 000000000..68027a4ec
--- /dev/null
+++ b/core/src/xmake/readline/readline.c
@@ -0,0 +1,65 @@
+/*!The Make-like Build Utility based on Lua
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Copyright (C) 2015 - 2017, TBOOX Open Source Group.
+ *
+ * @author TitanSnow
+ * @file readline.c
+ *
+ */
+
+#ifdef XM_CONFIG_API_HAVE_READLINE
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "readline"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+
+// readline wrapper
+tb_int_t xm_readline_readline(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // get the prompt
+ tb_char_t const* prompt = tb_null;
+ if (luaL_typename(lua, 1) != "nil")
+ prompt = luaL_checkstring(lua, 1);
+
+ // call readline
+ tb_char_t const* line = readline(prompt);
+ if (line)
+ lua_pushstring(lua, line);
+ else
+ lua_pushnil(lua);
+
+ // ok
+ return 1;
+}
+
+#endif