Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
lua-nucleo/c/lstack.c
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
61 lines (50 sloc)
1.39 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * lstack.h: Lua stack control functions | |
| * This file is a part of lua-nucleo library | |
| * Copyright (c) lua-nucleo authors (see file `COPYRIGHT` for the license) | |
| */ | |
| #include "lua-nucleo/lstack.h" | |
| #include "lua-nucleo/luainternals.h" | |
| int dump_lua_stack(lua_State * L, int base) | |
| { | |
| int top = lua_gettop(L); | |
| if (top == 0) | |
| { | |
| lua_pushliteral(L, "-- stack is empty --"); | |
| } | |
| else | |
| { | |
| int pos = 0; | |
| luaL_Buffer b; | |
| lua_pushcfunction(L, luaB_tostring); | |
| luaL_buffinit(L, &b); | |
| for (pos = top; pos > 0; --pos) | |
| { | |
| luaL_addstring(&b, (pos != base) ? "[" : "{"); | |
| lua_pushinteger(L, pos); | |
| luaL_addvalue(&b); | |
| luaL_addstring(&b, (pos != base) ? "] - " : "} -"); | |
| luaL_addstring(&b, luaL_typename(L, pos)); | |
| luaL_addstring(&b, " - `"); | |
| /* Call luaB_tostring() on value */ | |
| lua_pushvalue(L, top + 1); | |
| lua_pushvalue(L, pos); | |
| lua_call(L, 1, 1); | |
| luaL_addvalue(&b); | |
| luaL_addstring(&b, "'\n"); | |
| } | |
| luaL_pushresult(&b); | |
| lua_remove(L, -2); /* Pop luaB_tostring() */ | |
| if (lua_gettop(L) != top + 1) | |
| { | |
| /* Note: Can't use macros here, since macros use this function */ | |
| return luaL_error(L, "dumpstack not balanced (1)"); | |
| } | |
| } | |
| if (lua_gettop(L) != top + 1) | |
| { | |
| /* Note: Can't use macros here, since macros use this function */ | |
| return luaL_error(L, "dumpstack not balanced (2)"); | |
| } | |
| return 1; | |
| } |