/*-1* Copyright (c) 2020 Kyle Evans <[email protected]>2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6* 1. Redistributions of source code must retain the above copyright7* notice, this list of conditions and the following disclaimer.8* 2. Redistributions in binary form must reproduce the above copyright9* notice, this list of conditions and the following disclaimer in the10* documentation and/or other materials provided with the distribution.11*12* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND13* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE14* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE15* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE16* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL17* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS18* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)19* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT20* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY21* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF22* SUCH DAMAGE.23*/2425#include <lua.h>26#include "lauxlib.h"2728/* Open the pager. No arguments, no return value. */29static int30lpager_open(lua_State *L)31{3233pager_open();34return (0);35}3637/*38* Output to the pager. All arguments are interpreted as strings and passed to39* pager_output(). No return value.40*/41static int42lpager_output(lua_State *L)43{44const char *outstr;45int i;4647for (i = 1; i <= lua_gettop(L); i++) {48outstr = luaL_tolstring(L, i, NULL);49pager_output(outstr);50lua_pop(L, -1);51}5253return (0);54}5556/* Output to the pager from a file. Takes a filename, no return value. */57static int58lpager_file(lua_State *L)59{6061return (pager_file(luaL_checkstring(L, 1)));62}6364static int65lpager_close(lua_State *L)66{6768pager_close();69return (0);70}7172static const struct luaL_Reg pagerlib[] = {73{ "open", lpager_open },74{ "output", lpager_output },75{ "file", lpager_file },76{ "close", lpager_close },77{ NULL, NULL },78};7980int81luaopen_pager(lua_State *L)82{83luaL_newlib(L, pagerlib);84return 1;85}868788