Skip to content

Commit

Permalink
fix #4316: print warning/error when luadevs do dumb stuff ...
Browse files Browse the repository at this point in the history
  • Loading branch information
jK committed Feb 28, 2014
1 parent 4debcfc commit 693db61
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions rts/Lua/LuaSyncedRead.cpp
Expand Up @@ -4007,6 +4007,22 @@ int LuaSyncedRead::GetUnitCommands(lua_State* L)
const CFactoryCAI* factoryCAI = dynamic_cast<const CFactoryCAI*>(commandAI);
const CCommandQueue* queue = (factoryCAI == NULL) ? &commandAI->commandQue : &factoryCAI->newUnitCommands;

// performance relevant `debug` message
if (lua_isnoneornil(L, 2)) {
static int calls = 0;
static spring_time nextWarning = spring_gettime();
calls++;
if (spring_gettime() >= nextWarning) {
nextWarning = spring_gettime() + spring_secs(5);
if (calls > 1000) {
luaL_error(L,
"[%s] called too often without a 2nd argument to define maxNumCmds returned in the table, please check your code!\n"
"Especially when you only read the first cmd or want to check if the queue is non-empty, this can be a huge performance leak!\n", __FUNCTION__);
}
calls = 0;
}
}

const int numCmds = luaL_optint(L, 2, -1);
const bool cmdsTable = luaL_optboolean(L, 3, true); // deprecated, prefer to set 2nd arg to 0

Expand Down

0 comments on commit 693db61

Please sign in to comment.