diff --git a/.vscode/settings.json b/.vscode/settings.json index 72b65692085f624e7f1d5cefc6499181f23e66ab..1de93f55e29b31f1d925c4871435ba30b6cc0257 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 0000000000000000000000000000000000000000..69727ed9134b5205100a24a1b8f9426987aaa6f9 --- /dev/null +++ b/src/lua_2.c @@ -0,0 +1,125 @@ +/* +仿写的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 + + + + +#if !defined(LUA_INIT_VAR) +#define LUA_INIT_VAR "LUA_INIT" +#endif + +#define LUA_INITVARVERSION \ + LUA_INIT_VAR "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR + + + +#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); + 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; +} + + diff --git a/win_msys2_install.sh b/win_msys2_install.sh index de68a483a24f2141e26122434add29ec93eac7b6..d3213e06b0d904ef7467ec777f084ac02081503d 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