From 9146e4a02e4c760ab5a5fef0d6257f216916b6f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=94=A6=E6=B6=9B?= <1523628637@163.com> Date: Mon, 15 Apr 2024 02:20:55 +0800 Subject: [PATCH 1/5] test --- .vscode/settings.json | 4 +++- src/lua_2.c | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/lua_2.c diff --git a/.vscode/settings.json b/.vscode/settings.json index 72b6569..1de93f5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,8 @@ "algorithm": "c", "new": "c", "lprefix.h": "c", - "lstate.h": "c" + "lstate.h": "c", + "lua.h": "c", + "lauxlib.h": "c" } } \ No newline at end of file diff --git a/src/lua_2.c b/src/lua_2.c new file mode 100644 index 0000000..3a04430 --- /dev/null +++ b/src/lua_2.c @@ -0,0 +1,27 @@ +/* +仿写的lua.c +*/ +#define lua_c +#include "lprefix.h" +#include +#include +#include +#include +#include "lua.h" +#include "lualib.h" +#include "lauxlib.h" + +#if !defined(LUA_PROMPT) +#define LUA_PROMPT "> " +#define LUA_PROMT2 ">> " +#endif + +#if !defined(LUA_PROGNAME) +#define LUA_PROGNAME "lua" +#endif + +#if !defined(LUA_MAXINPUT) +#define LUA_MAXINPUT 512 +#endif + + -- Gitee From df4df9b35b0db58c4a639d867dd983950a5fb997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=94=A6=E6=B6=9B?= <1523628637@163.com> Date: Tue, 16 Apr 2024 02:06:24 +0800 Subject: [PATCH 2/5] study --- src/lua_2.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lua_2.c b/src/lua_2.c index 3a04430..f9bfe3b 100644 --- a/src/lua_2.c +++ b/src/lua_2.c @@ -25,3 +25,15 @@ #endif + + +#if !defined(LUA_INIT_VAR) +#define LUA_INIT_VAR "LUA_INIT" +#endif + +#define LUA_INITVARVERSION \ + LUA_INIT_VAR "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR + + + + -- Gitee From 9fa67837f8fdaa01e9f4c802170463b133c01fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=94=A6=E6=B6=9B?= <1523628637@163.com> Date: Thu, 18 Apr 2024 01:16:38 +0800 Subject: [PATCH 3/5] update --- src/lua_2.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/lua_2.c b/src/lua_2.c index f9bfe3b..e3f7fc2 100644 --- a/src/lua_2.c +++ b/src/lua_2.c @@ -36,4 +36,51 @@ +#if !defined(lua_stdin_is_tty) +#if defined(LUA_USE_POSIX) + +#include +#define lua_stdin_is_tty() isatty(0) + +#elif defined(LUA_USE_WINDOWS) + +#include +#define lua_stdin_is_tty() _isatty(_fileno(stdin)) + +#else +//iso +#define lua_stdin_is_tty() 1 + +#endif +#endif + + + +static lua_State* globalL = NULL; +static const char* progname = LUA_PROGNAME; + + +/* +hook set by signal to stop the interpreter; +*/ + +static void lstop(lua_State* L, lua_Debug* ar) { + lua_sethook(L, NULL, 0, 0); + luaL_error(L, "interrupted!"); +} + + + +static void laction(int i) { + signal(i, SIG_DFL); + lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); +} + + + +static void print_usage(const char* badoption) { + lua_writestringerror("%s:", progname); + +} + -- Gitee From f1077a8cad351a57a5d1905b4624812e8046a2f3 Mon Sep 17 00:00:00 2001 From: "jintao.wang" <15236286736@163.com> Date: Wed, 11 Jun 2025 16:57:09 +0800 Subject: [PATCH 4/5] src/lua_2.c --- src/lua_2.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/lua_2.c b/src/lua_2.c index e3f7fc2..69727ed 100644 --- a/src/lua_2.c +++ b/src/lua_2.c @@ -80,7 +80,46 @@ static void laction(int i) { static void print_usage(const char* badoption) { lua_writestringerror("%s:", progname); - + if(badoption[1] == 'e' || badoption[1] == 'l') + lua_writestringerror("'%s' needs argument\n",badoption); + else + lua_writestringerror("unrecognized option '%s'\n",badoption); + lua_writestringerror( + "usgage: %s [options] [script [args]]\n" + "Available options are:\n" + " -e stat execute string 'stat'\n" + " -i enter interactive mode after executing 'script'\n" + " -l name require library 'name'\n" + " -v show version information\n" + " -E ignore environment variables\n" + " -- stop handling options\n" + " - stop handling options and execute stdin\n" + ,progname); +} + +/* +check whether 'status' is not OK and,if so,prints the error message on the top of the stack; +*/ +static int report(lua_State* L,int status){ + if(status != LUA_OK){ + const char* msg=lua_tostring(L,-1); + l_message(progname, msg); + lua_pop(L, 1); /*remove message*/ + } + return status; +} + + +/* +message handler used to run all chunks; +*/ +static int msghandler(lua_State* L){ + const char*msg=lua_tostring(L, 1); + if(msg == NULL){ + + } + luaL_traceback(L, L , msg, 1); + return 1; } -- Gitee From f052a9789dba1cb2062c37f4f38e31300d8554df Mon Sep 17 00:00:00 2001 From: "jintao.wang" <15236286736@163.com> Date: Mon, 16 Jun 2025 11:43:05 +0800 Subject: [PATCH 5/5] sys2 install --- win_msys2_install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win_msys2_install.sh b/win_msys2_install.sh index de68a48..d3213e0 100644 --- a/win_msys2_install.sh +++ b/win_msys2_install.sh @@ -2,7 +2,7 @@ ##export INSTALL_TOP=/d/D/install_dir/lua_v532 && make linux -j4 && make install && make clean ##export INSTALL_TOP=/d/D/install_dir/lua_v532 && make mingw -j4 && make install && make clean -export INSTALL_TOP=/d/D/install_dir/lua_v532 && make generic -j4 && make install && make clean +export INSTALL_TOP=/d/D/install_dir/my_lua_v532 && make generic -j4 && make install && make clean -- Gitee