MCPcopy Create free account
hub / github.com/TASEmulators/fceux / toCStringConverter

Function toCStringConverter

src/lua-engine.cpp:1637–1788  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1635#define APPENDPRINT { int _n = snprintf(ptr, remaining,
1636#define END ); if(_n >= 0) { ptr += _n; remaining -= _n; } else { remaining = 0; } }
1637static void toCStringConverter(lua_State* L, int i, char*& ptr, int& remaining)
1638{
1639 if(remaining <= 0)
1640 return;
1641
1642 //const char* str = ptr; // for debugging
1643
1644 // if there is a __tostring metamethod then call it
1645 int usedMeta = luaL_callmeta(L, i, "__tostring");
1646 if(usedMeta)
1647 {
1648 std::vector<const void*>::const_iterator foundCycleIter = std::find(s_metacallStack.begin(), s_metacallStack.end(), lua_topointer(L,i));
1649 if(foundCycleIter != s_metacallStack.end())
1650 {
1651 lua_pop(L, 1);
1652 usedMeta = false;
1653 }
1654 else
1655 {
1656 s_metacallStack.push_back(lua_topointer(L,i));
1657 i = lua_gettop(L);
1658 }
1659 }
1660
1661 switch(lua_type(L, i))
1662 {
1663 case LUA_TNONE: break;
1664 case LUA_TNIL: APPENDPRINT "nil" END break;
1665 case LUA_TBOOLEAN: APPENDPRINT lua_toboolean(L,i) ? "true" : "false" END break;
1666 case LUA_TSTRING: APPENDPRINT "%s",lua_tostring(L,i) END break;
1667 case LUA_TNUMBER: APPENDPRINT "%.12g",lua_tonumber(L,i) END break;
1668 case LUA_TFUNCTION:
1669 /*if((L->base + i-1)->value.gc->cl.c.isC)
1670 {
1671 //lua_CFunction func = lua_tocfunction(L, i);
1672 //std::map<lua_CFunction, const char*>::iterator iter = s_cFuncInfoMap.find(func);
1673 //if(iter == s_cFuncInfoMap.end())
1674 goto defcase;
1675 //APPENDPRINT "function(%s)", iter->second END
1676 }
1677 else
1678 {
1679 APPENDPRINT "function(" END
1680 Proto* p = (L->base + i-1)->value.gc->cl.l.p;
1681 int numParams = p->numparams + (p->is_vararg?1:0);
1682 for (int n=0; n<p->numparams; n++)
1683 {
1684 APPENDPRINT "%s", getstr(p->locvars[n].varname) END
1685 if(n != numParams-1)
1686 APPENDPRINT "," END
1687 }
1688 if(p->is_vararg)
1689 APPENDPRINT "..." END
1690 APPENDPRINT ")" END
1691 }*/
1692 goto defcase;
1693 break;
1694defcase:default: APPENDPRINT "%s:%p",luaL_typename(L,i),lua_topointer(L,i) END break;

Callers 1

rawToCStringFunction · 0.85

Calls 10

luaL_callmetaFunction · 0.85
lua_topointerFunction · 0.85
lua_gettopFunction · 0.85
lua_typeFunction · 0.85
lua_tonumberFunction · 0.85
lua_checkstackFunction · 0.85
lua_nextFunction · 0.85
isalphaorunderscoreFunction · 0.85
lua_settopFunction · 0.85
beginMethod · 0.45

Tested by

no test coverage detected