Esempio n. 1
0
static LIST *luahelper_addtolist(ls_lua_State *L, LIST *list, int index)
{
    if (ls_lua_isboolean(L, index))
        return list_append(list, ls_lua_toboolean(L, index) ? "true" : "false", 0);

    if (ls_lua_isnumber(L, index)) {
        LIST* newList;
        ls_lua_pushvalue(L, index);
        newList = list_append(list, ls_lua_tostring(L, -1), 0);
        ls_lua_pop(L, 1);
        return newList;
    }

    if (ls_lua_isstring(L, index)) {
        const char* value = ls_lua_tostring(L, index);
        return list_append(list, value, 0);
    }

    else if (ls_lua_istable(L, index))
    {
        ls_lua_pushnil(L);
        while (ls_lua_next(L, index) != 0)
        {
            list = luahelper_addtolist(L, list, ls_lua_gettop(L));
            ls_lua_pop(L, 1);
        }
    }

    return list;
}
Esempio n. 2
0
const char* luahelper_linefilter(const char* line, size_t lineSize) {
    int ret;
    int top;
    char* out;

    if (linefilter_stack_position == -1) {
        fprintf(stderr, "jam: Line filter access not enabled.\n");
        exit(1);
    }

    ls_lua_init();

    top = ls_lua_gettop(L);
    ls_lua_pushvalue(L, linefilter_stack_position);
    ls_lua_pushlstring(L, line, lineSize);                    /* function line */
    ret = ls_lua_pcall(L, 1, 1, 0);
    if (ret != 0)
    {
        if (ls_lua_isstring(L, -1))
            fprintf(stderr, "jam: Error running line filter.\n%s\n", ls_lua_tostring(L, -1));
        ls_lua_settop(L, top);
        return NULL;
    }

    out = malloc(ls_lua_rawlen(L, -1) + 1);
    strcpy(out, ls_lua_tostring(L, -1));
    ls_lua_settop(L, top);

    return out;
}
Esempio n. 3
0
void luahelper_taskcancel(int taskid)
{
    int ret;

    ls_lua_init();

    ls_lua_rawgeti(L, LUA_REGISTRYINDEX, taskid);
    ls_lua_pushvalue(L, -1);
    ls_lua_getfield(L, -1, "cancel");
    ls_lua_pushvalue(L, -2);
    ls_lua_pushnumber(L, 0);
    ls_lua_pushboolean(L, 1);

    ret = ls_lua_pcall(L, 3, -1, 0);
    if (ret != 0)
    {
	if (ls_lua_isstring(L, -1))
	    printf("jam: Error running Lua task.cancel\n%s\n", ls_lua_tostring(L, -1));
	ls_lua_pop(L, 2);
	return;
    }

    ls_lua_pop(L, 1);
}
Esempio n. 4
0
int luahelper_taskisrunning(int taskid, int* returnValue)
{
	const char* status;
	ls_lua_init();

	ls_lua_rawgeti(L, LUA_REGISTRYINDEX, taskid);		/* lane_h */
	if (!ls_lua_istable(L, -1))
	{
		*returnValue = 1;
		ls_lua_pop(L, 1);
		return 0;
	}
	ls_lua_getfield(L, -1, "status");					/* lane_h status */

	status = ls_lua_tostring(L, -1);
	if (strcmp(status, "done") == 0)
	{
		int ret;

		ls_lua_pop(L, 1);								/* lane_h */
		ls_lua_getfield(L, -1, "join");					/* lane_h join(function) */
		ls_lua_pushvalue(L, -2);						/* lane_h join(function) lane_h */
		ret = ls_lua_pcall(L, 1, 1, 0);					/* lane_h ret */
		if (ret != 0)
		{
			if (ls_lua_isstring(L, -1))
				printf("jam: Error in Lua lane\n%s\n", ls_lua_tostring(L, -1));
			*returnValue = 1;
		}
		if (ls_lua_isnumber(L, -1))
			*returnValue = (int)ls_lua_tonumber(L, -1);
		ls_lua_pop(L, 2);
		ls_luaL_unref(L, LUA_REGISTRYINDEX, taskid);
		return 0;
	}
	else if (strcmp(status, "error") == 0  ||  strcmp(status, "cancelled") == 0)
	{
		int ret;

		*returnValue = 1;

		ls_lua_pop(L, 1);								/* lane_h */
		ls_lua_getfield(L, -1, "join");					/* lane_h join(function) */
		ls_lua_pushvalue(L, -2);						/* lane_h join(function) lane_h */
		ret = ls_lua_pcall(L, 1, 3, 0);					/* lane_h nil err stack_tbl */
		if (ret != 0)
		{
			if (ls_lua_isstring(L, -1))
				printf("jam: Error in Lua lane\n%s\n", ls_lua_tostring(L, -1));
			ls_lua_pop(L, 2);
			return 0;
		}

		if (ls_lua_isstring(L, -2))
		{
			printf("jam: Error in Lua lane\n%s\n", ls_lua_tostring(L, -2));
		}

		ls_lua_pop(L, 4);								/* */

		ls_luaL_unref(L, LUA_REGISTRYINDEX, taskid);
		return 0;
	}

	ls_lua_pop(L, 2);
	return 1;
}