Skip to content

Commit

Permalink
MFC r354245, r354833, r354837: add flua to the base system
Browse files Browse the repository at this point in the history
r354245: stand: consolidate knowledge of lua path

Multiple places coordinate to 'know' where lua scripts are installed. Knock
this down to being formally defined (and overridable) in exactly one spot,
defs.mk, and spread the knowledge to loaders and liblua alike. A future
commit will expose this to lua as loader.lua_path, so it can build absolute
paths to lua scripts as needed.

r354833: Add flua to the base system, install to /usr/libexec

FreeBSDlua ("flua") is a FreeBSD-private lua, flavored with whatever
extensions we need for base system operations. We currently support a subset
of lfs and lposix that are used in the rewrite of makesyscall.sh into lua,
added in r354786.

flua is intentionally written such that one can install standard lua and
some set of lua modules from ports and achieve the same effect.

linit_flua is a copy of linit.c from contrib/lua with lfs and lposix added
in. This is similar to what we do in stand/. linit.c has been renamed to
make it clear that this has flua-specific bits.

luaconf has been slightly obfuscated to make extensions more difficult. Part
of the problem is that flua is already hard enough to use as a bootstrap
tool because it's not in PATH- attempting to do extension loading would
require a special bootstrap version of flua with paths changed to protect
the innocent.

src.lua.mk has been added to make it easy for in-tree stuff to find flua,
whether it's bootstrap-flua or relying on PATH frobbing by Makefile.inc1.

r354837: flua: newer GCC complains about format-nonliteral at WARNS=2

Disable that one, too.
  • Loading branch information
kevans91 committed Dec 3, 2019
1 parent c1825b5 commit 9db4a15
Show file tree
Hide file tree
Showing 15 changed files with 1,123 additions and 5 deletions.
1 change: 1 addition & 0 deletions libexec/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SUBDIR= ${_atf} \
${_blacklistd-helper} \
${_comsat} \
${_dma} \
flua \
getty \
${_mail.local} \
${_makewhatis.local} \
Expand Down
38 changes: 38 additions & 0 deletions libexec/flua/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#! $FreeBSD$

.include <src.lua.mk>

LUASRC?= ${SRCTOP}/contrib/lua/src
.PATH: ${LUASRC}

PROG= flua
WARNS?= 2
MAN= # No manpage; this is internal.

CWARNFLAGS.gcc+= -Wno-format-nonliteral

LIBADD= m

# Core functions
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

# Library functions; any change to these likely needs an accompanying change
# in our custom linit_flua.c. We use our custom linit.c to make it easier to
# support bootstrap flua that may not have supporting local libraries.
SRCS+= lauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c \
lmathlib.c loslib.c lstrlib.c ltablib.c lutf8lib.c loadlib.c

# Entry point
SRCS+= lua.c

# FreeBSD Extensions
.PATH: ${.CURDIR}/modules
SRCS+= linit_flua.c
SRCS+= lfs.c lposix.c

CFLAGS+= -I${.CURDIR} -I${.CURDIR}/modules -I${LUASRC}
CFLAGS+= -DLUA_PROGNAME="\"${PROG}\""

.include <bsd.prog.mk>
73 changes: 73 additions & 0 deletions libexec/flua/linit_flua.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* $FreeBSD$ */
/*
** $Id: linit.c,v 1.39.1.1 2017/04/19 17:20:42 roberto Exp $
** Initialization of libraries for lua.c and other clients
** See Copyright Notice in lua.h
*/


#define linit_c
#define LUA_LIB

/*
** If you embed Lua in your program and need to open the standard
** libraries, call luaL_openlibs in your program. If you need a
** different set of libraries, copy this file to your project and edit
** it to suit your needs.
**
** You can also *preload* libraries, so that a later 'require' can
** open the library, which is already linked to the application.
** For that, do the following code:
**
** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
** lua_pushcfunction(L, luaopen_modname);
** lua_setfield(L, -2, modname);
** lua_pop(L, 1); // remove PRELOAD table
*/

#include "lprefix.h"


#include <stddef.h>

#include "lua.h"

#include "lualib.h"
#include "lauxlib.h"
#include "lfs.h"
#include "lposix.h"

/*
** these libs are loaded by lua.c and are readily available to any Lua
** program
*/
static const luaL_Reg loadedlibs[] = {
{"_G", luaopen_base},
{LUA_LOADLIBNAME, luaopen_package},
{LUA_COLIBNAME, luaopen_coroutine},
{LUA_TABLIBNAME, luaopen_table},
{LUA_IOLIBNAME, luaopen_io},
{LUA_OSLIBNAME, luaopen_os},
{LUA_STRLIBNAME, luaopen_string},
{LUA_MATHLIBNAME, luaopen_math},
{LUA_UTF8LIBNAME, luaopen_utf8},
{LUA_DBLIBNAME, luaopen_debug},
#if defined(LUA_COMPAT_BITLIB)
{LUA_BITLIBNAME, luaopen_bit32},
#endif
/* FreeBSD Extensions */
{"lfs", luaopen_lfs},
{"posix.unistd", luaopen_posix_unistd},
{NULL, NULL}
};


LUALIB_API void luaL_openlibs (lua_State *L) {
const luaL_Reg *lib;
/* "require" functions from 'loadedlibs' and set results to global table */
for (lib = loadedlibs; lib->func; lib++) {
luaL_requiref(L, lib->name, lib->func, 1);
lua_pop(L, 1); /* remove lib */
}
}

Loading

0 comments on commit 9db4a15

Please sign in to comment.