mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-24 06:12:27 +00:00
Make improvements
- Expand redbean UNIX module - Expand redbean documentation - Ensure Lua copyright is embedded in binary - Increase the PATH_MAX limit especially on NT - Use column major sorting for linenoise completions - Fix some suboptimalities in redbean's new UNIX API - Figured out right flags for Multics newline in raw mode
This commit is contained in:
parent
cf3174dc74
commit
2046c0d2ae
305 changed files with 6602 additions and 4221 deletions
64
third_party/lua/lrepl.c
vendored
64
third_party/lua/lrepl.c
vendored
|
@ -1,9 +1,36 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Lua │
|
||||
│ Copyright © 2004-2021 Lua.org, PUC-Rio. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#define lua_c
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/sigbits.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/nomultics.internal.h"
|
||||
#include "libc/intrin/spinlock.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
@ -12,13 +39,21 @@
|
|||
#include "third_party/linenoise/linenoise.h"
|
||||
#include "third_party/lua/lauxlib.h"
|
||||
#include "third_party/lua/lprefix.h"
|
||||
#include "third_party/lua/lrepl.h"
|
||||
#include "third_party/lua/lua.h"
|
||||
#include "third_party/lua/lualib.h"
|
||||
// clang-format off
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Lua 5.4.3 (MIT License)\\n\
|
||||
Copyright 1994–2021 Lua.org, PUC-Rio.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
|
||||
bool lua_repl_blocking;
|
||||
bool lua_repl_isterminal;
|
||||
_Alignas(64) char lualock;
|
||||
linenoiseCompletionCallback *lua_repl_completions_callback;
|
||||
_Alignas(64) char lua_repl_lock;
|
||||
struct linenoiseState *lua_repl_linenoise;
|
||||
static lua_State *globalL;
|
||||
static const char *g_progname;
|
||||
|
@ -63,6 +98,7 @@ void lua_readline_completions(const char *p, linenoiseCompletions *c) {
|
|||
lua_pop(L, 1);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
lua_repl_completions_callback(p, c);
|
||||
}
|
||||
|
||||
char *lua_readline_hint(const char *p, const char **ansi1, const char **ansi2) {
|
||||
|
@ -128,7 +164,7 @@ static ssize_t pushline (lua_State *L, int firstline) {
|
|||
if (lua_repl_isterminal) {
|
||||
prmt = strdup(get_prompt(L, firstline));
|
||||
lua_pop(L, 1); /* remove prompt */
|
||||
_spunlock(&lualock);
|
||||
LUA_REPL_UNLOCK;
|
||||
rc = linenoiseEdit(lua_repl_linenoise, prmt, &b, !firstline || lua_repl_blocking);
|
||||
free(prmt);
|
||||
if (rc != -1) {
|
||||
|
@ -138,11 +174,11 @@ static ssize_t pushline (lua_State *L, int firstline) {
|
|||
linenoiseHistorySave(g_historypath);
|
||||
}
|
||||
}
|
||||
_spinlock(&lualock);
|
||||
LUA_REPL_LOCK;
|
||||
} else {
|
||||
_spunlock(&lualock);
|
||||
LUA_REPL_UNLOCK;
|
||||
b = linenoiseGetLine(stdin);
|
||||
_spinlock(&lualock);
|
||||
LUA_REPL_LOCK;
|
||||
rc = b ? 1 : -1;
|
||||
}
|
||||
if (rc == -1 || (!rc && !b)) {
|
||||
|
@ -208,7 +244,7 @@ static int multiline (lua_State *L) {
|
|||
|
||||
void lua_initrepl(lua_State *L, const char *progname) {
|
||||
const char *prompt;
|
||||
_spinlock(&lualock);
|
||||
LUA_REPL_LOCK;
|
||||
g_progname = progname;
|
||||
if ((lua_repl_isterminal = linenoiseIsTerminal())) {
|
||||
linenoiseSetCompletionCallback(lua_readline_completions);
|
||||
|
@ -224,20 +260,18 @@ void lua_initrepl(lua_State *L, const char *progname) {
|
|||
}
|
||||
lua_repl_linenoise = linenoiseBegin(prompt, 0, 1);
|
||||
lua_pop(L, 1); /* remove prompt */
|
||||
__nomultics = 2;
|
||||
__replmode = true;
|
||||
}
|
||||
_spunlock(&lualock);
|
||||
LUA_REPL_UNLOCK;
|
||||
}
|
||||
|
||||
|
||||
void lua_freerepl(void) {
|
||||
_spinlock(&lualock);
|
||||
__nomultics = false;
|
||||
LUA_REPL_LOCK;
|
||||
__replmode = false;
|
||||
linenoiseEnd(lua_repl_linenoise);
|
||||
free(g_historypath);
|
||||
_spunlock(&lualock);
|
||||
LUA_REPL_UNLOCK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -254,16 +288,16 @@ int lua_loadline (lua_State *L) {
|
|||
ssize_t rc;
|
||||
int status;
|
||||
lua_settop(L, 0);
|
||||
_spinlock(&lualock);
|
||||
LUA_REPL_LOCK;
|
||||
if ((rc = pushline(L, 1)) != 1) {
|
||||
_spunlock(&lualock);
|
||||
LUA_REPL_UNLOCK;
|
||||
return rc - 1; /* eof or error */
|
||||
}
|
||||
if ((status = addreturn(L)) != LUA_OK) /* 'return ...' did not work? */
|
||||
status = multiline(L); /* try as command, maybe with continuation lines */
|
||||
lua_remove(L, 1); /* remove line from the stack */
|
||||
lua_assert(lua_gettop(L) == 1);
|
||||
_spunlock(&lualock);
|
||||
LUA_REPL_UNLOCK;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue