Files
integration/luprex/core/cpp/print.hpp

55 lines
1.4 KiB
C++

/////////////////////////////////////////////////////////
//
// Pretty-print routine.
//
// The pretty-printer can be called from C++ or Lua.
//
/////////////////////////////////////////////////////////
#ifndef PRINT_HPP
#define PRINT_HPP
#include "luastack.hpp"
// This file provides these functions for lua.
//
// They direct all output to std::cout
//
extern "C" {
void luai_writestring(const char *s, size_t len);
void luai_writeline();
}
// Output a simple value to a stream.
//
// If the value is a string, number, boolean, or nil, it is
// quoted and output to the stream, and this function returns
// true. Otherwise, this function returns false and nothing
// is sent to the stream.
//
bool string_quote(LuaStack &LS, LuaSlot val, std::ostream *os);
// Pretty print to a stream.
//
// If indent is >=0, the output is indented. If indent<0, then
// the output is emitted without newlines or indentation.
//
// Maxlen specifies the maximum number of characters output. If
// this is exceeded, then the printout is truncated.
//
void pprint(LuaStack &LS, LuaSlot val, bool indent, std::ostream *os);
// The following lua interfaces to this code are included:
//
// pprint(expr, expr, expr...)
//
// - pretty print the specified expression to stdout.
//
// string.pprint(expr, indent)
//
// - pretty print the specified expression, return the result as a string.
//
int lfn_pprint_pprint(lua_State *L);
int lfn_string_pprint(lua_State *L);
#endif // PRINT_HPP