Example #1
0
void runtasks(LState *const rootState) {
	lua_state = lua_state->next;
	while (lua_state) {
		LState *nextState = NULL;
		bool stillRunning;
		if (!lua_state->updated && !lua_state->paused) {
			jmp_buf	errorJmp;
			lua_state->errorJmp = &errorJmp;
			if (setjmp(errorJmp)) {
				lua_Task *t, *m;
				for (t = lua_state->task; t != NULL;) {
					m = t->next;
					luaM_free(t);
					t = m;
				}
				stillRunning = false;
				lua_state->task = NULL;
			} else {
				if (lua_state->task) {
					stillRunning = luaD_call(lua_state->task->some_base, lua_state->task->some_results);
				} else {
					StkId base = lua_state->Cstack.base;
					luaD_openstack((lua_state->stack.top - lua_state->stack.stack) - base);
					set_normalized(lua_state->stack.stack + lua_state->Cstack.base, &lua_state->taskFunc);
					stillRunning = luaD_call(base + 1, 255);
				}
			}
			nextState = lua_state->next;
			// The state returned. Delete it
			if (!stillRunning) {
				lua_statedeinit(lua_state);
				luaM_free(lua_state);
			} else {
				lua_state->updated = true;
			}
		} else {
			nextState = lua_state->next;
		}
		lua_state = nextState;
	}

	// Restore the value of lua_state to the main script
	lua_state = rootState;
	// Check for states that may have been created in this run.
	LState *state = lua_state->next;
	while (state) {
		if (!state->paused && !state->updated) {
			// New state! Run a new pass.
			runtasks(rootState);
			return;
		}
		state = state->next;
	}
}
Example #2
0
void lua_runtasks() {
	if (!lua_state || !lua_state->next) {
		return;
	}

	// Mark all the states to be updated
	LState *state = lua_state->next;
	do {
		state->updated = false;
		state = state->next;
	} while	(state);

	// And run them
	runtasks(lua_state);
}
Example #3
0
void lua_runtasks() {
	if (!lua_state || !lua_state->next) {
		return;
	}

	// Mark all the states to be updated
	LState *state = lua_state->next;
	do {
		if (state->sleepFor > 0) {
			state->sleepFor -= g_grim->getFrameTime();
		} else {
			state->updated = false;
		}
		state = state->next;
	} while	(state);

	// And run them
	runtasks(lua_state);
}