Date: Mon, 12 Feb 2018 15:31:53 +0000 (UTC) From: Warner Losh <imp@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329166 - in head: . share/mk stand stand/common stand/liblua stand/liblua32 sys/sys tools/build/options Message-ID: <201802121531.w1CFVrGi007406@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: imp Date: Mon Feb 12 15:31:53 2018 New Revision: 329166 URL: https://svnweb.freebsd.org/changeset/base/329166 Log: Add Lua as a scripting langauge to /boot/loader liblua glues the lua run time into the boot loader. It implements all the runtime routines that lua expects. In addition, it has a few standard 'C' headers that nueter various aspects of the LUA build that are too specific to lua to be in libsa. Many refinements from the original code to improve implementation and the number of included lua libraries. Use int64_t for lua_Number. Have "/boot/lua" be the default module path. Numerous cleanups from the original GSoC project, including hacking libsa to allow lua to be built with only one change outside luaconf.h. Add the final bit of lua glue to bring in liblua and plug into the multiple interpreter framework, previously committed. Add LOADER_LUA option, currently off by default. Presently, this is an experimental option. One must opt-in to using this by defining WITH_LOADER_LUA and WITHOUT_FORTH. It's been lightly tested, so keep a backup copy of your old loader handy. The menu code, coming in the next commit, hasn't been exhaustively tested. A LUA boot loader is 60k larger than a FORTH one, which is 80k larger than a no-interpreter one. Subtle changes in size may tip things past some subtle limit (the binary is ~430k now when built with LUA). A future version may offer coexistance. Bump FreeBSD version to 1200058 to mark the milestone. Pedro Souza's 2014 Summer of Code project. Rui Paulo, Pedro Arthur, Zakary Nafziger and Wojciech A. Koszek also contributed. Warner Losh reworked it extensively into its current form. Obtained from: https://wiki.freebsd.org/SummerOfCode2014/LuaLoader Sponsored by: Google Summer of Code Relnotes: Yes MFC After: 1 month Differential Review: https://reviews.freebsd.org/D14295 Added: head/stand/common/interp_lua.c (contents, props changed) head/stand/liblua/ head/stand/liblua/Makefile (contents, props changed) head/stand/liblua/float.h (contents, props changed) head/stand/liblua/locale.h (contents, props changed) head/stand/liblua/lstd.c (contents, props changed) head/stand/liblua/lstd.h (contents, props changed) head/stand/liblua/luaconf.h (contents, props changed) head/stand/liblua/lutils.c (contents, props changed) head/stand/liblua/lutils.h (contents, props changed) head/stand/liblua/math.h (contents, props changed) head/stand/liblua32/ head/stand/liblua32/Makefile (contents, props changed) head/stand/lua.mk (contents, props changed) head/tools/build/options/WITH_LOADER_LUA (contents, props changed) Modified: head/UPDATING head/share/mk/src.opts.mk head/stand/Makefile head/stand/Makefile.amd64 head/stand/defs.mk head/stand/loader.mk head/sys/sys/param.h Modified: head/UPDATING ============================================================================== --- head/UPDATING Mon Feb 12 14:48:20 2018 (r329165) +++ head/UPDATING Mon Feb 12 15:31:53 2018 (r329166) @@ -51,6 +51,14 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 12.x IS SLOW: ****************************** SPECIAL WARNING: ****************************** +20180212: + FreeBSD boot loader enhanced with Lua scripting. It's purely opt-in for + now by building WITH_LOADER_LUA and WITHOUT_FORTH in /etc/src.conf. + Co-existance for the transition period will come shortly. Booting is a + complex environment and test coverage for Lua-enabled loaders has been + thin, so it would be prudent to assume it might not work and make + provisions for backup boot methods. + 20180211: devmatch functionality has been turned on in devd. It will automatically load drivers for unattached devices. This may cause unexpected drivers to Modified: head/share/mk/src.opts.mk ============================================================================== --- head/share/mk/src.opts.mk Mon Feb 12 14:48:20 2018 (r329165) +++ head/share/mk/src.opts.mk Mon Feb 12 15:31:53 2018 (r329166) @@ -184,6 +184,7 @@ __DEFAULT_NO_OPTIONS = \ LIBSOFT \ LOADER_FIREWIRE \ LOADER_FORCE_LE \ + LOADER_LUA \ NAND \ OFED \ OPENLDAP \ Modified: head/stand/Makefile ============================================================================== --- head/stand/Makefile Mon Feb 12 14:48:20 2018 (r329165) +++ head/stand/Makefile Mon Feb 12 15:31:53 2018 (r329166) @@ -8,6 +8,9 @@ SUBDIR+= libsa SUBDIR+= ficl SUBDIR+= forth .endif +.if ${MK_LOADER_LUA} != "no" +SUBDIR+= liblua +.endif SUBDIR+= man Modified: head/stand/Makefile.amd64 ============================================================================== --- head/stand/Makefile.amd64 Mon Feb 12 14:48:20 2018 (r329165) +++ head/stand/Makefile.amd64 Mon Feb 12 15:31:53 2018 (r329166) @@ -7,6 +7,9 @@ SUBDIR+= zfs zfs32 .if ${MK_FORTH} != "no" SUBDIR+= ficl32 .endif +.if ${MK_LOADER_LUA} != "no" +SUBDIR+= liblua32 +.endif SUBDIR+= efi SUBDIR+= userboot Added: head/stand/common/interp_lua.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/stand/common/interp_lua.c Mon Feb 12 15:31:53 2018 (r329166) @@ -0,0 +1,164 @@ +/*- + * Copyright (c) 2011 Wojciech A. Koszek <wkoszek@FreeBSD.org> + * Copyright (c) 2014 Pedro Souza <pedrosouza@freebsd.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <stand.h> +#include "bootstrap.h" + +#define lua_c + +#include "lstd.h" + +#include <lua.h> +#include <ldebug.h> +#include <lauxlib.h> +#include <lualib.h> +#include <lutils.h> + +struct interp_lua_softc { + lua_State *luap; +}; + +static struct interp_lua_softc lua_softc; + +#ifdef LUA_DEBUG +#define LDBG(...) do { \ + printf("%s(%d): ", __func__, __LINE__); \ + printf(__VA_ARGS__); \ + printf("\n"); \ +} while (0) +#else +#define LDBG(...) +#endif + + +static void * +interp_lua_realloc(void *ud __unused, void *ptr, size_t osize __unused, size_t nsize) +{ + + if (nsize == 0) { + free(ptr); + return NULL; + } + return realloc(ptr, nsize); +} + +/* + * The libraries commented out below either lack the proper + * support from libsa, or they are unlikely to be useful + * in the bootloader, so have been commented out. + */ +static const luaL_Reg loadedlibs[] = { + {"_G", luaopen_base}, + {LUA_LOADLIBNAME, luaopen_package}, +// {LUA_COLIBNAME, luaopen_coroutine}, +// {LUA_TABLIBNAME, luaopen_table}, + {LUA_STRLIBNAME, luaopen_string}, +// {LUA_IOLIBNAME, luaopen_io}, +// {LUA_OSLIBNAME, luaopen_os}, +// {LUA_MATHLIBNAME, luaopen_math}, +// {LUA_UTF8LIBNAME, luaopen_utf8}, +// {LUA_DBLIBNAME, luaopen_debug}, + {NULL, NULL} +}; + +void +interp_init(void) +{ + lua_State *luap; + struct interp_lua_softc *softc = &lua_softc; + const char *filename; + const luaL_Reg *lib; + + setenv("script.lang", "lua", 1); + LDBG("creating context"); + + luap = lua_newstate(interp_lua_realloc, NULL); + if (luap == NULL) { + printf("problem initializing the Lua interpreter\n"); + abort(); + } + softc->luap = luap; + register_utils(luap); + + /* "require" functions from 'loadedlibs' and set results to global table */ + for (lib = loadedlibs; lib->func; lib++) { + luaL_requiref(luap, lib->name, lib->func, 1); + lua_pop(luap, 1); /* remove lib */ + } + + filename = "/boot/lua/loader.lua"; + if (interp_include(filename) != 0) { + const char *errstr = lua_tostring(luap, -1); + errstr = errstr == NULL ? "unknown" : errstr; + printf("Startup errorr in %s:\nLUA ERROR: %s.\n", filename, errstr); + lua_pop(luap, 1); + } +} + +int +interp_run(const char *line) +{ + int argc; + char **argv; + lua_State *luap; + struct interp_lua_softc *softc = &lua_softc; + int status; + + luap = softc->luap; + LDBG("executing line..."); + if ((status = luaL_dostring(luap, line)) != 0) { + /* + * If we could not parse the line as Lua syntax, + * try parsing it as a loader command. + */ + lua_pop(luap, 1); + if (parse(&argc, &argv, line) == 0) { + status = interp_builtin_cmd(argc, argv); + if (status != CMD_OK) + printf("Command failed\n"); + free(argv); + } else { + printf("Failed to parse \'%s\'\n", line); + status = -1; + } + } + + return (status == 0 ? CMD_OK : CMD_ERROR); +} + +int +interp_include(const char *filename) +{ + struct interp_lua_softc *softc = &lua_softc; + + LDBG("loading file %s", filename); + + return (luaL_dofile(softc->luap, filename)); +} Modified: head/stand/defs.mk ============================================================================== --- head/stand/defs.mk Mon Feb 12 14:48:20 2018 (r329165) +++ head/stand/defs.mk Mon Feb 12 15:31:53 2018 (r329166) @@ -23,6 +23,8 @@ EFIINCMD= ${EFIINC}/${MACHINE} FDTSRC= ${BOOTSRC}/fdt FICLSRC= ${BOOTSRC}/ficl LDRSRC= ${BOOTSRC}/common +LIBLUASRC= ${BOOTSRC}/liblua +LUASRC= ${SRCTOP}/contrib/lua/src SASRC= ${BOOTSRC}/libsa SYSDIR= ${SRCTOP}/sys UBOOTSRC= ${BOOTSRC}/uboot Added: head/stand/liblua/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/stand/liblua/Makefile Mon Feb 12 15:31:53 2018 (r329166) @@ -0,0 +1,38 @@ +# $FreeBSD$ + +.include <bsd.init.mk> + +.PATH: ${LUASRC} +.PATH: ${LIBLUASRC} + +LIB= lua +INTERNALLIB= + +# Core Lua. +SRCS= lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c \ + lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c \ + ltm.c lundump.c lvm.c lzio.c +SRCS+= lauxlib.c lbaselib.c lstrlib.c loadlib.c + +# These aren't yet included, but link now, omitting them saves 15k +#SRCS+= lcorolib.c ldblib.c lutf8lib.c + +# These aren't yet compatible with the boot environment, and some may never be +#SRCS+= lbitlib.c liolib.c lmathlib.c loslib.c ltablib.c + +# Our utilities. +SRCS+= lstd.c lutils.c + +WARNS= 3 + +CFLAGS+= -DLUA_FLOAT_TYPE=LUA_FLOAT_INT64 +CFLAGS+= -DLUA_PATH_DEFAULT=\"/boot/lua/\?.lua\" +CFLAGS+= -ffreestanding -nostdlib -DBOOT_LUA -DLUA_USE_POSIX +CFLAGS+= -fno-stack-protector -D__BSD_VISIBLE +CFLAGS+= -I${BOOTSRC}/include -I${LIBLUASRC} -I${LUASRC} -I${LDRSRC} + +.if ${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 0 +CFLAGS+= -fPIC +.endif + +.include <bsd.lib.mk> Added: head/stand/liblua/float.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/stand/liblua/float.h Mon Feb 12 15:31:53 2018 (r329166) @@ -0,0 +1,32 @@ +/*- + * Copyright (c) 2018 M Warner Losh + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Empty file to keep lua build happy. Lua expects to have to include float.h + * but the int64_t number implementation doesn't need it. + */ Added: head/stand/liblua/locale.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/stand/liblua/locale.h Mon Feb 12 15:31:53 2018 (r329166) @@ -0,0 +1,27 @@ +/*- + * Copyright (c) 2018 M Warner Losh + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ Added: head/stand/liblua/lstd.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/stand/liblua/lstd.c Mon Feb 12 15:31:53 2018 (r329166) @@ -0,0 +1,182 @@ +/*- + * Copyright (c) 2014 Pedro Souza <pedrosouza@freebsd.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include "lstd.h" +#include "math.h" + +FILE * +fopen(const char *filename, const char *mode) +{ + struct stat st; + int fd; + FILE *f; + + if (mode == NULL || mode[0] != 'r') + return NULL; + + fd = open(filename, O_RDONLY); + if (fd < 0) + return NULL; + + f = malloc(sizeof(FILE)); + if (f == NULL) { + close(fd); + return NULL; + } + + if (fstat(fd, &st) != 0) { + free(f); + close(fd); + return (NULL); + } + + f->fd = fd; + f->offset = 0; + f->size = st.st_size; + + return (f); +} + + +FILE * +freopen(const char *filename, const char *mode, FILE *stream) +{ + fclose(stream); + return (fopen(filename, mode)); +} + +size_t +fread(void *ptr, size_t size, size_t count, FILE *stream) +{ + size_t r; + + if (stream == NULL) + return 0; + r = (size_t)read(stream->fd, ptr, size * count); + stream->offset += r; + + return (r); +} + +int +fclose(FILE *stream) +{ + if (stream == NULL) + return EOF; + close(stream->fd); + free(stream); + + return (0); +} + +int +ferror(FILE *stream) +{ + + return (stream == NULL || stream->fd < 0); +} + +int +feof(FILE *stream) +{ + + if (stream == NULL) + return 1; + + return (stream->offset >= stream->size); +} + +int +getc(FILE *stream) +{ + char ch; + size_t r; + + if (stream == NULL) + return EOF; + r = read(stream->fd, &ch, 1); + if (r == 1) + return ch; + return EOF; +} + +void +luai_writestring(const char *s, int i) +{ + + while (i-- > 0) + putchar(*s++); +} + +/* + * These routines from here on down are to implement the lua math + * library, but that's not presently included by default. They are + * little more than placeholders to allow compilation due to linkage + * issues with upstream Lua. + */ + +int64_t +lstd_pow(int64_t x, int64_t y) +{ + int64_t rv = 1; + + if (y < 0) + return 0; + rv = x; + while (--y) + rv *= x; + + return rv; +} + +int64_t +lstd_floor(int64_t x) +{ + + return (x); +} + +int64_t +lstd_fmod(int64_t a, int64_t b) +{ + + return (a % b); +} + +/* + * This can't be implemented, so maybe it should just abort. + */ +int64_t +lstd_frexp(int64_t a, int *y) +{ + *y = 0; + + return 0; +} Added: head/stand/liblua/lstd.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/stand/liblua/lstd.h Mon Feb 12 15:31:53 2018 (r329166) @@ -0,0 +1,74 @@ +/*- + * Copyright (c) 2014 Pedro Souza <pedrosouza@freebsd.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef LSTD_H +#define LSTD_H + +#include <stand.h> +#include <sys/types.h> +#include <sys/stdint.h> +#include <limits.h> +#include <string.h> +#include <machine/stdarg.h> + +typedef struct FILE +{ + int fd; + size_t offset; + size_t size; +} FILE; + +FILE *fopen(const char *filename, const char *mode); +FILE *freopen( const char *filename, const char *mode, FILE *stream); +size_t fread(void *ptr, size_t size, size_t count, FILE *stream); +int fclose(FILE *stream); +int ferror(FILE *stream); +int feof(FILE *stream); +int getc(FILE * stream); + +#ifndef EOF +#define EOF (-1) +#endif + +#define stdin ((FILE*)NULL) +#define stdout 1 + +#ifndef BUFSIZ +#define BUFSIZ 512 +#endif + +#define lua_writestringerror(s, p) do { printf((s), (p)); } while (0) + +void luai_writestring(const char *, int); + +#define lua_writestring(s,l) luai_writestring(s,l) + +#define fflush /* */ +#define fgets(b, l, s) fgetstr((b), (l), 0) + +#endif /* LSTD_H */ Added: head/stand/liblua/luaconf.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/stand/liblua/luaconf.h Mon Feb 12 15:31:53 2018 (r329166) @@ -0,0 +1,811 @@ +/* $FreeBSD$ */ +/* +** $Id: luaconf.h,v 1.259 2016/12/22 13:08:50 roberto Exp $ +** Configuration file for Lua +** See Copyright Notice in lua.h +*/ + + +#ifndef luaconf_h +#define luaconf_h + +#include <limits.h> +#include <stddef.h> + + +/* +** =================================================================== +** Search for "@@" to find all configurable definitions. +** =================================================================== +*/ + + +/* +** {==================================================================== +** System Configuration: macros to adapt (if needed) Lua to some +** particular platform, for instance compiling it with 32-bit numbers or +** restricting it to C89. +** ===================================================================== +*/ + +/* +@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. You +** can also define LUA_32BITS in the make file, but changing here you +** ensure that all software connected to Lua will be compiled with the +** same configuration. +*/ +/* #define LUA_32BITS */ + + +/* +@@ LUA_USE_C89 controls the use of non-ISO-C89 features. +** Define it if you want Lua to avoid the use of a few C99 features +** or Windows-specific features on Windows. +*/ +/* #define LUA_USE_C89 */ + + +/* +** By default, Lua on Windows use (some) specific Windows features +*/ +#if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE) +#define LUA_USE_WINDOWS /* enable goodies for regular Windows */ +#endif + + +#if defined(LUA_USE_WINDOWS) +#define LUA_DL_DLL /* enable support for DLL */ +#define LUA_USE_C89 /* broadly, Windows is C89 */ +#endif + + +#if defined(LUA_USE_LINUX) +#define LUA_USE_POSIX +#define LUA_USE_DLOPEN /* needs an extra library: -ldl */ +#define LUA_USE_READLINE /* needs some extra libraries */ +#endif + + +#if defined(LUA_USE_MACOSX) +#define LUA_USE_POSIX +#define LUA_USE_DLOPEN /* MacOS does not need -ldl */ +#define LUA_USE_READLINE /* needs an extra library: -lreadline */ +#endif + + +/* +@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for +** C89 ('long' and 'double'); Windows always has '__int64', so it does +** not need to use this case. +*/ +#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS) +#define LUA_C89_NUMBERS +#endif + + + +/* +@@ LUAI_BITSINT defines the (minimum) number of bits in an 'int'. +*/ +/* avoid undefined shifts */ +#if ((INT_MAX >> 15) >> 15) >= 1 +#define LUAI_BITSINT 32 +#else +/* 'int' always must have at least 16 bits */ +#define LUAI_BITSINT 16 +#endif + + +/* +@@ LUA_INT_TYPE defines the type for Lua integers. +@@ LUA_FLOAT_TYPE defines the type for Lua floats. +** Lua should work fine with any mix of these options (if supported +** by your C compiler). The usual configurations are 64-bit integers +** and 'double' (the default), 32-bit integers and 'float' (for +** restricted platforms), and 'long'/'double' (for C compilers not +** compliant with C99, which may not have support for 'long long'). +*/ + +/* predefined options for LUA_INT_TYPE */ +#define LUA_INT_INT 1 +#define LUA_INT_LONG 2 +#define LUA_INT_LONGLONG 3 + +/* predefined options for LUA_FLOAT_TYPE */ +#define LUA_FLOAT_FLOAT 1 +#define LUA_FLOAT_DOUBLE 2 +#define LUA_FLOAT_LONGDOUBLE 3 +#define LUA_FLOAT_INT64 4 + +#if defined(LUA_32BITS) /* { */ +/* +** 32-bit integers and 'float' +*/ +#if LUAI_BITSINT >= 32 /* use 'int' if big enough */ +#define LUA_INT_TYPE LUA_INT_INT +#else /* otherwise use 'long' */ +#define LUA_INT_TYPE LUA_INT_LONG +#endif +#define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT + +#elif defined(LUA_C89_NUMBERS) /* }{ */ +/* +** largest types available for C89 ('long' and 'double') +*/ +#define LUA_INT_TYPE LUA_INT_LONG +#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE + +#endif /* } */ + + +/* +** default configuration for 64-bit Lua ('long long' and 'double') +*/ +#if !defined(LUA_INT_TYPE) +#define LUA_INT_TYPE LUA_INT_LONGLONG +#endif + +#if !defined(LUA_FLOAT_TYPE) +#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE +#endif + +/* }================================================================== */ + + + + +/* +** {================================================================== +** Configuration for Paths. +** =================================================================== +*/ + +/* +** LUA_PATH_SEP is the character that separates templates in a path. +** LUA_PATH_MARK is the string that marks the substitution points in a +** template. +** LUA_EXEC_DIR in a Windows path is replaced by the executable's +** directory. +*/ +#define LUA_PATH_SEP ";" +#define LUA_PATH_MARK "?" +#define LUA_EXEC_DIR "!" + + +/* +@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for +** Lua libraries. +@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for +** C libraries. +** CHANGE them if your machine has a non-conventional directory +** hierarchy or if you want to install your libraries in +** non-conventional directories. +*/ +#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 "\\" +#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" +#define LUA_CPATH_DEFAULT \ + LUA_CDIR"?.dll;" \ + LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \ + LUA_CDIR"loadall.dll;" ".\\?.dll" + +#else /* }{ */ + +#define LUA_ROOT "/usr/local/" +#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR "/" +#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR "/" +#ifndef LUA_PATH_DEFAULT +#define LUA_PATH_DEFAULT \ + LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \ + "./?.lua;" "./?/init.lua" +#endif +#define LUA_CPATH_DEFAULT \ + LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so" +#endif /* } */ + + +/* +@@ 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(_WIN32) +#define LUA_DIRSEP "\\" +#else +#define LUA_DIRSEP "/" +#endif + +/* }================================================================== */ + + +/* +** {================================================================== +** Marks for exported symbols in the C code +** =================================================================== +*/ + +/* +@@ LUA_API is a mark for all core API functions. +@@ LUALIB_API is a mark for all auxiliary library functions. +@@ LUAMOD_API is a mark for all standard library opening functions. +** CHANGE them if you need to define those functions in some special way. +** For instance, if you want to create one Windows DLL with the core and +** 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 */ +#define LUALIB_API LUA_API +#define LUAMOD_API LUALIB_API + + +/* +@@ LUAI_FUNC is a mark for all extern functions that are not to be +** exported to outside modules. +@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables +** that are not to be exported to outside modules (LUAI_DDEF for +** definitions and LUAI_DDEC for declarations). +** CHANGE them if you need to mark them in some special way. Elf/gcc +** (versions 3.2 and later) mark them as "hidden" to optimize access +** when Lua is compiled as a shared library. Not all elf targets support +** this attribute. Unfortunately, gcc does not offer a way to check +** whether the target offers that support, and those without support +** 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("hidden"))) extern +#else /* }{ */ +#define LUAI_FUNC extern +#endif /* } */ + +#define LUAI_DDEC LUAI_FUNC +#define LUAI_DDEF /* empty */ + +/* }================================================================== */ + + +/* +** {================================================================== +** Compatibility with previous versions +** =================================================================== +*/ + +/* +@@ LUA_COMPAT_5_2 controls other macros for compatibility with Lua 5.2. +@@ LUA_COMPAT_5_1 controls other macros for compatibility with Lua 5.1. +** You can define it to get all options, or change specific options +** to fit your specific needs. +*/ +#if defined(LUA_COMPAT_5_2) /* { */ + +/* +@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated +** functions in the mathematical library. +*/ +#define LUA_COMPAT_MATHLIB + +/* +@@ LUA_COMPAT_BITLIB controls the presence of library 'bit32'. +*/ +#define LUA_COMPAT_BITLIB + +/* +@@ LUA_COMPAT_IPAIRS controls the effectiveness of the __ipairs metamethod. +*/ +#define LUA_COMPAT_IPAIRS + +/* +@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for +** manipulating other integer types (lua_pushunsigned, lua_tounsigned, +** luaL_checkint, luaL_checklong, etc.) +*/ +#define LUA_COMPAT_APIINTCASTS + +#endif /* } */ + + +#if defined(LUA_COMPAT_5_1) /* { */ + +/* Incompatibilities from 5.2 -> 5.3 */ +#define LUA_COMPAT_MATHLIB +#define LUA_COMPAT_APIINTCASTS + +/* +@@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'. +** You can replace it with 'table.unpack'. +*/ +#define LUA_COMPAT_UNPACK + +/* +@@ LUA_COMPAT_LOADERS controls the presence of table 'package.loaders'. +** You can replace it with 'package.searchers'. +*/ +#define LUA_COMPAT_LOADERS + +/* +@@ macro 'lua_cpcall' emulates deprecated function lua_cpcall. +** You can call your C function directly (with light C functions). +*/ +#define lua_cpcall(L,f,u) \ + (lua_pushcfunction(L, (f)), \ + lua_pushlightuserdata(L,(u)), \ + lua_pcall(L,1,0,0)) + + +/* +@@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library. +** You can rewrite 'log10(x)' as 'log(x, 10)'. +*/ +#define LUA_COMPAT_LOG10 + +/* +@@ LUA_COMPAT_LOADSTRING defines the function 'loadstring' in the base +** library. You can rewrite 'loadstring(s)' as 'load(s)'. +*/ +#define LUA_COMPAT_LOADSTRING + +/* +@@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library. +*/ +#define LUA_COMPAT_MAXN + +/* +@@ The following macros supply trivial compatibility for some +** changes in the API. The macros themselves document how to +** change your code to avoid using them. +*/ +#define lua_strlen(L,i) lua_rawlen(L, (i)) + +#define lua_objlen(L,i) lua_rawlen(L, (i)) + +#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ) +#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT) + +/* +@@ LUA_COMPAT_MODULE controls compatibility with previous +** module functions 'module' (Lua) and 'luaL_register' (C). +*/ +#define LUA_COMPAT_MODULE + +#endif /* } */ + + *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802121531.w1CFVrGi007406>