mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 11:18:30 +00:00
Fix bugs and make improvements to redbean
- Abort if .init.lua fails - Refactor redbean to use new append library - Use first certificate if SNI routing fails - Use function/data sections when building Lua - Don't use self-signed auto-generated cert for client - Add -D staging dirs to redbean lua module default path
This commit is contained in:
parent
55a15c204e
commit
aeeb851422
26 changed files with 703 additions and 513 deletions
9
third_party/lua/loadlib.c
vendored
9
third_party/lua/loadlib.c
vendored
|
@ -16,6 +16,8 @@
|
|||
#include "third_party/lua/lua.h"
|
||||
#include "third_party/lua/lualib.h"
|
||||
|
||||
const char *g_lua_path_default = LUA_PATH_DEFAULT;
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
/*
|
||||
|
@ -728,12 +730,17 @@ static void createclibstable (lua_State *L) {
|
|||
}
|
||||
|
||||
|
||||
static const char *GetLuaPathDefault(void) {
|
||||
return g_lua_path_default;
|
||||
}
|
||||
|
||||
|
||||
LUAMOD_API int luaopen_package (lua_State *L) {
|
||||
createclibstable(L);
|
||||
luaL_newlib(L, pk_funcs); /* create 'package' table */
|
||||
createsearcherstable(L);
|
||||
/* set paths */
|
||||
setpath(L, "path", LUA_PATH_VAR, LUA_PATH_DEFAULT);
|
||||
setpath(L, "path", LUA_PATH_VAR, g_lua_path_default);
|
||||
setpath(L, "cpath", LUA_CPATH_VAR, LUA_CPATH_DEFAULT);
|
||||
/* store config information */
|
||||
lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n"
|
||||
|
|
44
third_party/lua/lua.h
vendored
44
third_party/lua/lua.h
vendored
|
@ -1,15 +1,8 @@
|
|||
/*
|
||||
** $Id: lua.h $
|
||||
** Lua - A Scripting Language
|
||||
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
|
||||
** See Copyright Notice at the end of this file
|
||||
*/
|
||||
|
||||
#ifndef lua_h
|
||||
#define lua_h
|
||||
|
||||
#ifndef COSMOPOLITAN_THIRD_PARTY_LUA_LUA_H_
|
||||
#define COSMOPOLITAN_THIRD_PARTY_LUA_LUA_H_
|
||||
#include "third_party/lua/luaconf.h"
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
/* clang-format off */
|
||||
|
||||
#define LUA_VERSION_MAJOR "5"
|
||||
|
@ -489,29 +482,8 @@ struct lua_Debug {
|
|||
|
||||
/* }====================================================================== */
|
||||
|
||||
extern const char *g_lua_path_default;
|
||||
|
||||
/******************************************************************************
|
||||
* Copyright (C) 1994-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.
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#endif
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_THIRD_PARTY_LUA_LUA_H_ */
|
||||
|
|
5
third_party/lua/lua.mk
vendored
5
third_party/lua/lua.mk
vendored
|
@ -60,6 +60,11 @@ o/$(MODE)/third_party/lua/lauxlib.o: \
|
|||
OVERRIDE_CFLAGS += \
|
||||
-DSTACK_FRAME_UNLIMITED
|
||||
|
||||
$(THIRD_PARTY_LUA_OBJS): \
|
||||
OVERRIDE_CFLAGS += \
|
||||
-ffunction-sections \
|
||||
-fdata-sections
|
||||
|
||||
.PHONY: o/$(MODE)/third_party/lua
|
||||
o/$(MODE)/third_party/lua: \
|
||||
$(THIRD_PARTY_LUA_BINS) \
|
||||
|
|
79
third_party/lua/luaconf.h
vendored
79
third_party/lua/luaconf.h
vendored
|
@ -1,17 +1,13 @@
|
|||
/*
|
||||
** $Id: luaconf.h $
|
||||
** Configuration file for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
#ifndef luaconf_h
|
||||
#define luaconf_h
|
||||
|
||||
#define LUA_USE_POSIX
|
||||
#include "libc/assert.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/limits.h"
|
||||
#include "third_party/gdtoa/gdtoa.h"
|
||||
|
||||
#define LUA_USE_POSIX
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
/*
|
||||
|
@ -193,63 +189,20 @@
|
|||
*/
|
||||
|
||||
#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
|
||||
#if defined(_WIN32) /* { */
|
||||
/*
|
||||
** In Windows, any exclamation mark ('!') in the path is replaced by the
|
||||
** path of the directory of the executable file of the current process.
|
||||
*/
|
||||
#define LUA_LDIR "!\\lua\\"
|
||||
#define LUA_CDIR "!\\"
|
||||
#define LUA_SHRDIR "!\\..\\share\\lua\\" LUA_VDIR "\\"
|
||||
|
||||
#if !defined(LUA_PATH_DEFAULT)
|
||||
#define LUA_PATH_DEFAULT \
|
||||
LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
|
||||
LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \
|
||||
LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \
|
||||
".\\?.lua;" ".\\?\\init.lua"
|
||||
#endif
|
||||
|
||||
#if !defined(LUA_CPATH_DEFAULT)
|
||||
#define LUA_CPATH_DEFAULT \
|
||||
LUA_CDIR"?.dll;" \
|
||||
LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \
|
||||
LUA_CDIR"loadall.dll;" ".\\?.dll"
|
||||
#endif
|
||||
|
||||
#else /* }{ */
|
||||
|
||||
#define LUA_ROOT "zip:"
|
||||
#define LUA_LDIR LUA_ROOT ".lua/"
|
||||
#define LUA_CDIR LUA_ROOT ".lua/"
|
||||
|
||||
#if !defined(LUA_PATH_DEFAULT)
|
||||
#define LUA_PATH_DEFAULT \
|
||||
LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua"
|
||||
#endif
|
||||
|
||||
#if !defined(LUA_CPATH_DEFAULT)
|
||||
#define LUA_CPATH_DEFAULT \
|
||||
LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"
|
||||
#endif
|
||||
|
||||
#endif /* } */
|
||||
|
||||
#define LUA_PATH_DEFAULT LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" "./?.lua;" "./?/init.lua"
|
||||
#define LUA_CPATH_DEFAULT LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"
|
||||
|
||||
/*
|
||||
@@ LUA_DIRSEP is the directory separator (for submodules).
|
||||
** CHANGE it if your machine does not use "/" as the directory separator
|
||||
** and is not Windows. (On Windows Lua automatically uses "\".)
|
||||
*/
|
||||
#if !defined(LUA_DIRSEP)
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define LUA_DIRSEP "\\"
|
||||
#else
|
||||
#define LUA_DIRSEP "/"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* }================================================================== */
|
||||
|
||||
|
@ -269,20 +222,8 @@
|
|||
** the libraries, you may want to use the following definition (define
|
||||
** LUA_BUILD_AS_DLL to get it).
|
||||
*/
|
||||
#if defined(LUA_BUILD_AS_DLL) /* { */
|
||||
|
||||
#if defined(LUA_CORE) || defined(LUA_LIB) /* { */
|
||||
#define LUA_API __declspec(dllexport)
|
||||
#else /* }{ */
|
||||
#define LUA_API __declspec(dllimport)
|
||||
#endif /* } */
|
||||
|
||||
#else /* }{ */
|
||||
|
||||
#define LUA_API extern
|
||||
|
||||
#endif /* } */
|
||||
|
||||
|
||||
/*
|
||||
** More often than not the libs go together with the core.
|
||||
|
@ -305,12 +246,7 @@
|
|||
** give a warning about it. To avoid these warnings, change to the
|
||||
** default definition.
|
||||
*/
|
||||
#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
|
||||
defined(__ELF__) /* { */
|
||||
#define LUAI_FUNC /* __attribute__((visibility("internal"))) */ extern
|
||||
#else /* }{ */
|
||||
#define LUAI_FUNC extern
|
||||
#endif /* } */
|
||||
|
||||
#define LUAI_DDEC(dec) LUAI_FUNC dec
|
||||
#define LUAI_DDEF /* empty */
|
||||
|
@ -710,8 +646,7 @@
|
|||
@@ LUA_USE_APICHECK turns on several consistency checks on the C API.
|
||||
** Define it as a help when debugging C code.
|
||||
*/
|
||||
#if defined(LUA_USE_APICHECK)
|
||||
#include <assert.h>
|
||||
#if IsModeDbg()
|
||||
#define luai_apicheck(l,e) assert(e)
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue