예제 #1
0
void boxUpValue_start(lua_State *luaState) {
	LClosure *closure;
	closure = (LClosure *)lua_newLclosure(luaState, 1, hvalue(&luaState->l_gt));
	pushClosure(luaState, (Closure *)closure);
	// >>>>> ...... func
	closure->p = makeFakeProto(luaState, 1);

	// Temporarily initialize the upvalue to nil
	lua_pushnil(luaState);
	closure->upvals[0] = makeUpValue(luaState, -1);
	lua_pop(luaState, 1);
}
예제 #2
0
파일: menus.c 프로젝트: bzero/POSApp
closure* showMenu2(MenuItem_t* items, int numItems, closure* cl)
{
	closure* next_cl = NULL;
	int isFinished = FALSE; 
	bool multipage, firstpage, lastpage;
	CHECK(NULL!=cl);
	firstpage = cl->page==0;
	multipage = (numItems > PAGE_ITEMS);
	lastpage = (cl->page+1)*PAGE_ITEMS >= numItems;
	CHECK(SUCCESS==printMenu2(items,numItems,multipage,lastpage,cl->page));
	while (!isFinished) {
		char szKey;
		long lOSEvent = wait_event();
		if (lOSEvent & EVT_KBD) {
			if (read(g_conHandle, &szKey, 1) > 0) {
				int i;
				const MenuItem_t* curr = items;
				szKey = convertKey (szKey);	
				if (KEY_HASH == szKey || KEY_BACK == szKey) {
					if (multipage && !firstpage) {
						cl->page--;
						next_cl = cl;
						isFinished = TRUE;
					} else {
						next_cl = popClosure(cl);
						isFinished = TRUE;
					}
				} else if (szKey == KEY_STAR) {
					if (multipage && !lastpage) {
						cl->page++;
						next_cl = cl;
						isFinished = TRUE;
					}
				} else {
					for (i=0; i<numItems; i++) {
						if (curr->key == szKey) {
							CHECK(NULL!=(curr->func));
							next_cl = pushClosure(cl, curr->func, curr->param);
							isFinished = TRUE;
							break;
						}
						curr++;
					}
				}
			}
		}
	}
	return next_cl;
}
예제 #3
0
파일: menus.c 프로젝트: bzero/POSApp
closure* showMenuWithTimeout(const MenuItem_t* items, int numItems, closure* cl, long msecs, char defKey)
{
	closure* next_cl = NULL;
	int isFinished = FALSE; 
	CHECK(NULL!=cl);
	CHECK(SUCCESS==printMenu(items, numItems));
	while (!isFinished) {
		char szKey = 0;
		long lOSEvent;		
		if (msecs > 0) {
			CHECK(0<=set_timer(msecs, EVT_TIMER));
		}
		lOSEvent = wait_event();
		if (lOSEvent & EVT_KBD || lOSEvent & EVT_TIMER) {	
			if (lOSEvent & EVT_TIMER) {
				szKey = defKey;
			}	
			if (0!=szKey || read(g_conHandle, &szKey, 1) > 0) {
				int i;
				const MenuItem_t* curr = items;
				szKey = convertKey (szKey);				
				for (i=0; i<numItems; i++) {
					if (curr->key == szKey) {
						CHECK(NULL!=(curr->func));
						next_cl = pushClosure(cl, curr->func, NULL);
						isFinished = TRUE;
						break;
					}
					curr++;
				}
			}
			CHECK(SUCCESS==printMenu(items,numItems));
		} 	
	}
	return next_cl;
}