예제 #1
0
파일: thread.c 프로젝트: dotlive/LearnLUA
/*
 * SDL.createThread(name, source)
 *
 * Create a separate thread of execution. It creates a new Lua state that
 * does not share any data frmo the parent process.
 *
 * Arguments:
 *	name, the thread name
 *	source, a path to a Lua file or a function to call
 *
 * Returns:
 *	The thread object or nil
 *	The error message
 */
static int
l_thread_create(lua_State *L)
{
	const char *name = luaL_checkstring(L, 1);
	int ret, iv;
	LuaThread *thread;

	if ((thread = calloc(1, sizeof (LuaThread))) == NULL)
		return commonPushErrno(L, 1);

	thread->L = luaL_newstate();
	luaL_openlibs(thread->L);

	ret = threadDump(L, thread->L, 2);

	/* If return number is 2, it is nil and the error */
	if (ret == 2)
		goto failure;

	/* Iterate over the arguments to pass to the callback */
	for (iv = 3; iv <= lua_gettop(L); ++iv) {
		Variant *v = variantGet(L, iv);

		if (v == NULL) {
			commonPushErrno(L, 1);
			goto failure;
		}

		variantPush(thread->L, v);
		variantFree(v);
	}

	thread->ptr = SDL_CreateThread((SDL_ThreadFunction)callback, name, thread);
	if (thread->ptr == NULL) {
		commonPushSDLError(L, 1);
		goto failure;
	}

	SDL_AtomicIncRef(&thread->ref);

	return commonPush(L, "p", ThreadName, thread);

failure:
	lua_close(thread->L);
	free(thread);

	return 2;
}
예제 #2
0
파일: DomNode.c 프로젝트: ADTSH/io
void *domNodeGetValueVariant(DOM_NODE *node, enum VariantType type)
{
	return variantGet(type, domNodeGetValue(node));
}