| 1220 | } |
| 1221 | |
| 1222 | LuaValue LuaEngine::popLuaValue(lua_State* state) { |
| 1223 | lua_checkstack(state, 1); |
| 1224 | |
| 1225 | LuaValue result; |
| 1226 | starAssert(!lua_isnone(state, -1)); |
| 1227 | switch (lua_type(state, -1)) { |
| 1228 | case LUA_TNIL: { |
| 1229 | lua_pop(state, 1); |
| 1230 | break; |
| 1231 | } |
| 1232 | case LUA_TBOOLEAN: { |
| 1233 | result = lua_toboolean(state, -1) != 0; |
| 1234 | lua_pop(state, 1); |
| 1235 | break; |
| 1236 | } |
| 1237 | case LUA_TNUMBER: { |
| 1238 | if (lua_isinteger(state, -1)) { |
| 1239 | result = lua_tointeger(state, -1); |
| 1240 | lua_pop(state, 1); |
| 1241 | } else { |
| 1242 | result = lua_tonumber(state, -1); |
| 1243 | lua_pop(state, 1); |
| 1244 | } |
| 1245 | break; |
| 1246 | } |
| 1247 | case LUA_TSTRING: { |
| 1248 | result = LuaString(LuaDetail::LuaHandle(RefPtr<LuaEngine>(this), popHandle(state))); |
| 1249 | break; |
| 1250 | } |
| 1251 | case LUA_TTABLE: { |
| 1252 | result = LuaTable(LuaDetail::LuaHandle(RefPtr<LuaEngine>(this), popHandle(state))); |
| 1253 | break; |
| 1254 | } |
| 1255 | case LUA_TFUNCTION: { |
| 1256 | result = LuaFunction(LuaDetail::LuaHandle(RefPtr<LuaEngine>(this), popHandle(state))); |
| 1257 | break; |
| 1258 | } |
| 1259 | case LUA_TTHREAD: { |
| 1260 | result = LuaThread(LuaDetail::LuaHandle(RefPtr<LuaEngine>(this), popHandle(state))); |
| 1261 | break; |
| 1262 | } |
| 1263 | case LUA_TUSERDATA: { |
| 1264 | if (lua_getmetatable(state, -1) == 0) { |
| 1265 | lua_pop(state, 1); |
| 1266 | throw LuaException("Userdata in popLuaValue missing metatable"); |
| 1267 | } |
| 1268 | lua_pop(state, 1); |
| 1269 | result = LuaUserData(LuaDetail::LuaHandle(RefPtr<LuaEngine>(this), popHandle(state))); |
| 1270 | break; |
| 1271 | } |
| 1272 | default: { |
| 1273 | lua_pop(state, 1); |
| 1274 | throw LuaException("Unsupported type in popLuaValue"); |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | return result; |
| 1279 | } |
no test coverage detected