fix(util/sexpr): nested Lua objects
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
2ef7b9be2f
commit
d31cde473e
4 changed files with 26 additions and 2 deletions
|
@ -310,6 +310,7 @@ pretty_fn::pretty_fn(environment const & env, options const & o):
|
|||
}
|
||||
|
||||
format pretty_fn::operator()(expr const & e) {
|
||||
m_depth = 0; m_num_steps = 0;
|
||||
return pp_child(purify(e), 0).first;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,6 +81,29 @@ int equal(lua_State * L, int idx1, int idx2) {
|
|||
#endif
|
||||
}
|
||||
|
||||
char const * tostring(lua_State * L, int idx) {
|
||||
if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */
|
||||
switch (lua_type(L, idx)) {
|
||||
case LUA_TNUMBER:
|
||||
case LUA_TSTRING:
|
||||
lua_pushvalue(L, idx);
|
||||
break;
|
||||
case LUA_TBOOLEAN:
|
||||
lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false"));
|
||||
break;
|
||||
case LUA_TNIL:
|
||||
lua_pushliteral(L, "nil");
|
||||
break;
|
||||
default: {
|
||||
std::ostringstream strm;
|
||||
strm << lua_typename(L, idx) << ": " << lua_topointer(L, idx);
|
||||
lua_pushstring(L, strm.str().c_str());
|
||||
break;
|
||||
}}
|
||||
}
|
||||
return lua_tostring(L, -1);
|
||||
}
|
||||
|
||||
int get_nonnil_top(lua_State * L) {
|
||||
int top = lua_gettop(L);
|
||||
while (top > 0 && lua_isnil(L, top))
|
||||
|
@ -181,4 +204,3 @@ void check_atleast_num_args(lua_State * L, int low) {
|
|||
if (lua_gettop(L) < low) throw exception("too few arguments to function");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ size_t objlen(lua_State * L, int idx);
|
|||
void dofile(lua_State * L, char const * fname);
|
||||
void dostring(lua_State * L, char const * str);
|
||||
void pcall(lua_State * L, int nargs, int nresults, int errorfun);
|
||||
char const * tostring (lua_State * L, int idx);
|
||||
/**
|
||||
\brief Return true iff coroutine is done, false if it has yielded,
|
||||
and throws an exception if error.
|
||||
|
|
|
@ -441,7 +441,7 @@ public:
|
|||
virtual void display(std::ostream & out) const {
|
||||
lua_State * L = m_ref.get_state();
|
||||
m_ref.push();
|
||||
out << lua_tostring(L, -1);
|
||||
out << tostring(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue