Fix util::ostringstream, fix pretty-printing, stub out new globals

This commit is contained in:
2023-03-05 01:51:25 -05:00
parent db234c2934
commit 86a27ef2d4
13 changed files with 455 additions and 282 deletions

View File

@@ -711,21 +711,61 @@ LuaDefine(math_randomstate, "seed",
LuaSandboxBuiltin(math_randomseed, "", "");
LuaDefine(pprint, "obj1,obj2,...",
"|Pretty-print object or objects.") {
LuaDefine(pprint, "obj1, obj2, ...",
"|Pretty-print the specified objects."
"|"
"|See also: pprintx, which has a lot more options."
"|This function uses the default options: pretty print indented,"
"|start at indentation level zero, and always expand the"
"|top-level table."
"|") {
World *w = World::fetch_global_pointer(L);
std::ostream *ostream = w->lthread_print_stream();
int n = lua_gettop(L);
LuaStack LS(L);
for (int i = 1; i <= lua_gettop(L); i++) {
for (int i = 1; i <= n; i++) {
LuaSpecial root(i);
pprint(LS, root, true, ostream);
(*ostream) << std::endl;
pprint(LS, root, PrettyPrintOptions(), ostream);
if (i < n) (*ostream) << "\n";
}
(*ostream) << std::endl;
return LS.result();
}
LuaDefine(pprintx, "options",
"|Pretty-print the specified object, with options"
"|"
"|Options is a table with these fields:"
"|"
"| value - the object to pretty-print"
"| indent - if false, suppress newlines and indentation (default: true)"
"| level - base level of indentation (default: zero)"
"| expand - if true, force expansion of top-level table (default: false)"
"|"
"|About the expand flag: normally, when you print a class, it just "
"|prints '<class name>', and when you print a tangible, it just"
"|prints '<tangible id>'. But sometimes, you want to see the details."
"|The expand flag forces it to expand the top-level table, even if the"
"|top-level table is a tangible or class."
"|") {
World *w = World::fetch_global_pointer(L);
std::ostream *ostream = w->lthread_print_stream();
LuaArg loptions;
LuaVar value;
LuaStack LS(L, loptions, value);
PrettyPrintOptions options;
LuaKeywordParser kp(LS, loptions);
options.parse(kp);
if (!kp.parse(value, "value")) {
LS.set(value, LuaNil);
}
kp.final_check_throw();
pprint(LS, value, options, ostream);
return LS.result();
}
LuaDefine(print, "obj1,obj2,...",
LuaDefine(print, "obj1, obj2, ...",
"|Print object or objects.") {
World *w = World::fetch_global_pointer(L);
std::ostream *ostream = w->lthread_print_stream();