| 215 | |
| 216 | |
| 217 | int LuaGLQueryMgr::RunQuery(lua_State* L) { |
| 218 | static bool running = false; |
| 219 | |
| 220 | if (running) { |
| 221 | luaL_error(L, "not re-entrant"); |
| 222 | } |
| 223 | |
| 224 | const LuaGLQuery* query = CheckLuaGLQuery(L, 1); |
| 225 | if (!query->IsValid()) { |
| 226 | luaL_error(L, "invalid query object"); |
| 227 | } |
| 228 | |
| 229 | int funcIndex = 2; |
| 230 | |
| 231 | GLenum target = query->GetTarget(); |
| 232 | if (lua_israwnumber(L, funcIndex)) { |
| 233 | target = (GLenum)lua_toint(L, funcIndex); |
| 234 | funcIndex++; |
| 235 | } |
| 236 | |
| 237 | luaL_checktype(L, funcIndex, LUA_TFUNCTION); |
| 238 | |
| 239 | running = true; |
| 240 | glBeginQuery(target, query->GetID()); |
| 241 | const int top = lua_gettop(L); |
| 242 | const int error = lua_pcall(L, top - funcIndex, LUA_MULTRET, 0); |
| 243 | glEndQuery(target); |
| 244 | running = false; |
| 245 | |
| 246 | if (error != 0) { |
| 247 | LuaLog(1, "gl.RunQuery: error(%i) = %s", error, lua_tostring(L, -1)); |
| 248 | lua_error(L); |
| 249 | } |
| 250 | |
| 251 | return lua_gettop(L) - (funcIndex - 1); |
| 252 | } |
| 253 | |
| 254 | |
| 255 | int LuaGLQueryMgr::GetQuery(lua_State* L) { |
nothing calls this directly
no test coverage detected