MCPcopy Create free account
hub / github.com/cuberite/cuberite / CopyStackFrom

Method CopyStackFrom

src/Bindings/LuaState.cpp:1201–1269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1199
1200
1201int cLuaState::CopyStackFrom(cLuaState & a_SrcLuaState, int a_SrcStart, int a_SrcEnd)
1202{
1203 /*
1204 // DEBUG:
1205 LOGD("Copying stack values from %d to %d", a_SrcStart, a_SrcEnd);
1206 a_SrcLuaState.LogStack("Src stack before copying:");
1207 LogStack("Dst stack before copying:");
1208 */
1209 for (int i = a_SrcStart; i <= a_SrcEnd; ++i)
1210 {
1211 int t = lua_type(a_SrcLuaState, i);
1212 switch (t)
1213 {
1214 case LUA_TNIL:
1215 {
1216 lua_pushnil(m_LuaState);
1217 break;
1218 }
1219 case LUA_TSTRING:
1220 {
1221 AString s;
1222 a_SrcLuaState.ToString(i, s);
1223 Push(s);
1224 break;
1225 }
1226 case LUA_TBOOLEAN:
1227 {
1228 bool b = (tolua_toboolean(a_SrcLuaState, i, false) != 0);
1229 Push(b);
1230 break;
1231 }
1232 case LUA_TNUMBER:
1233 {
1234 lua_Number d = tolua_tonumber(a_SrcLuaState, i, 0);
1235 Push(d);
1236 break;
1237 }
1238 case LUA_TUSERDATA:
1239 {
1240 // Get the class name:
1241 const char * type = NULL;
1242 if (lua_getmetatable(a_SrcLuaState, i) == 0)
1243 {
1244 LOGWARNING("%s: Unknown class in pos %d, cannot copy.", __FUNCTION__, i);
1245 lua_pop(m_LuaState, i - a_SrcStart);
1246 return -1;
1247 }
1248 lua_rawget(a_SrcLuaState, LUA_REGISTRYINDEX); // Stack +1
1249 type = lua_tostring(a_SrcLuaState, -1);
1250 lua_pop(a_SrcLuaState, 1); // Stack -1
1251
1252 // Copy the value:
1253 void * ud = tolua_touserdata(a_SrcLuaState, i, NULL);
1254 tolua_pushusertype(m_LuaState, ud, type);
1255 break;
1256 }
1257 default:
1258 {

Callers 1

Calls 11

lua_typeFunction · 0.85
lua_pushnilFunction · 0.85
tolua_tobooleanFunction · 0.85
tolua_tonumberFunction · 0.85
lua_getmetatableFunction · 0.85
lua_rawgetFunction · 0.85
tolua_touserdataFunction · 0.85
tolua_pushusertypeFunction · 0.85
lua_typenameFunction · 0.85
LogStackMethod · 0.80
ToStringMethod · 0.45

Tested by

no test coverage detected