示例#1
0
LIST *
builtin_luafile(
		PARSE	*parse,
		LOL		*args,
		int		*jmp)
{
    int top;
    int ret;
    LIST *l2;
    int index = 0;

    LIST *l = lol_get(args, 0);
    if (!l) {
	printf("jam: No argument passed to LuaFile\n");
	exit(EXITBAD);
    }
    ls_lua_init();
    top = ls_lua_gettop(L);
    ls_lua_newtable(L);
    for (l2 = lol_get(args, 1); l2; l2 = l2->next) {
	ls_lua_pushstring(L, l2->string);
	ls_lua_rawseti(L, -2, ++index);
    }
    ls_lua_setfield(L, LUA_GLOBALSINDEX, "arg");
    ret = ls_luaL_loadfile(L, l->string);
    return ls_lua_callhelper(top, ret);
}
示例#2
0
LIST *
builtin_luafile(
        PARSE    *parse,
        LOL        *args,
        int        *jmp)
{
    int top;
    int ret;
    LISTITEM *l2;
    int index = 0;

    LIST *l = lol_get(args, 0);
    if (!list_first(l)) {
        printf("jam: No argument passed to LuaFile\n");
        exit(EXITBAD);
    }
    ls_lua_init();
    top = ls_lua_gettop(L);
    ls_lua_newtable(L);
    for (l2 = list_first(lol_get(args, 1)); l2; l2 = list_next(l2)) {
        ls_lua_pushstring(L, list_value(l2));
        ls_lua_rawseti(L, -2, ++index);
    }
    ls_lua_setglobal(L, "arg");
    ret = ls_luaL_loadfile(L, list_value(list_first(l)));
    return ls_lua_callhelper(top, ret);
}
示例#3
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;
}
示例#4
0
int luahelper_taskadd(const char* taskscript)
{
    int ret;
    int ref;
    size_t taskscriptlen = strlen(taskscript);
    char* newTaskScript;

    ls_lua_init();

    ls_lua_getfield(L, LUA_GLOBALSINDEX, "lanes");			/* lanes */
    ls_lua_getfield(L, -1, "gen");							/* lanes gen */
    ls_lua_pushstring(L, "*");								/* lanes gen * */

    newTaskScript = malloc( taskscriptlen + 1 );
    strncpy(newTaskScript, taskscript, taskscriptlen);
    newTaskScript[taskscriptlen] = 0;
    ret = ls_luaL_loadstring(L, newTaskScript);			/* lanes gen * script */
    if (ret != 0)
    {
	if (ls_lua_isstring(L, -1))
	    printf("jam: Error compiling Lua lane\n%s\n", ls_lua_tostring(L, -1));
	ls_lua_pop(L, 2);
	printf("%s\n", newTaskScript);
	free(newTaskScript);
	return -1;
    }

    free(newTaskScript);
    ret = ls_lua_pcall(L, 2, 1, 0);						/* lanes lane_h */
    if (ret != 0)
    {
	if (ls_lua_isstring(L, -1))
	    printf("jam: Error creating Lua lane\n%s\n", ls_lua_tostring(L, -1));
	ls_lua_pop(L, 2);
	return -1;
    }

    if (!ls_lua_isfunction(L, -1))							/* lanes lane_h */
    {
	ls_lua_pop(L, 2);
	return -1;
    }

    ret = ls_lua_pcall(L, 0, 1, 0);						/* lanes ret */
    if (ret != 0)
    {
	if (ls_lua_isstring(L, -1))
	    printf("jam: Error calling Lua lane\n%s\n", ls_lua_tostring(L, -1));
	ls_lua_pop(L, 2);
	return -1;
    }

    ref = ls_luaL_ref(L, LUA_REGISTRYINDEX);
    ls_lua_pop(L, 1);
    return ref;
}
示例#5
0
int luahelper_push_linefilter(const char* actionName) {
    ls_lua_init();

    ls_lua_getglobal(L, "LineFilters");                        /* LineFilters */
    ls_lua_getfield(L, -1, actionName);                        /* LineFilters function */
    if (!ls_lua_isfunction(L, -1)) {
        ls_lua_pop(L, 2);
        return 0;
    }
    ls_lua_remove(L, -2);
    linefilter_stack_position = ls_lua_gettop(L);
    return 1;
}
示例#6
0
int luahelper_md5callback(const char *filename, MD5SUM sum, const char* callback)
{
    int ret;

    ls_lua_init();

    ls_lua_getfield(L, LUA_GLOBALSINDEX, callback);
    if (!ls_lua_isfunction(L, -1))
    {
	ls_lua_pop(L, 1);
	printf("jam: Error calling Lua md5 callback '%s'.\n", callback);
	memset(sum, 0, sizeof(MD5SUM));
	return 0;
    }

    ls_lua_pushstring(L, filename);
    ret = ls_lua_pcall(L, 1, 1, 0);
    if (ret != 0)
    {
	if (ls_lua_isstring(L, -1))
	    printf("jam: Error running Lua md5 callback\n%s\n", ls_lua_tostring(L, -1));
	ls_lua_pop(L, 1);
	memset(sum, 0, sizeof(MD5SUM));
	return 0;
    }

    if (ls_lua_isnil(L, -1))
    {
	memset(sum, 0, sizeof(MD5SUM));
	ls_lua_pop(L, 1);
	return 0;
    }

    if (!ls_lua_isstring(L, -1)  ||  ls_lua_objlen(L, -1) != sizeof(MD5SUM))
    {
	printf("jam: Error running Lua md5 callback '%s'.\n", callback);
	memset(sum, 0, sizeof(MD5SUM));
	ls_lua_pop(L, 1);
	return 0;
    }

    memcpy(sum, ls_lua_tostring(L, -1), sizeof(MD5SUM));
    ls_lua_pop(L, 1);
    return 1;
}
示例#7
0
LIST *
builtin_luastring(
		  PARSE	*parse,
		  LOL		*args,
		  int		*jmp)
{
    int top;
    int ret;

    LIST *l = lol_get(args, 0);
    if (!l)
    {
	printf("jam: No argument passed to LuaString\n");
	exit(EXITBAD);
    }
    ls_lua_init();
    top = ls_lua_gettop(L);
    ret = ls_luaL_loadstring(L, l->string);
    return ls_lua_callhelper(top, ret);
}
示例#8
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);
}
示例#9
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;
}
示例#10
0
int luahelper_taskadd(const char* taskscript, LOL* args)
{
    int ret;
    int ref;
    size_t taskscriptlen = strlen(taskscript);
    char* newTaskScript;
	int i;

    ls_lua_init();

    ls_lua_getglobal(L, "lanes");                             /* lanes */
    ls_lua_getfield(L, -1, "gen");                            /* lanes gen */
    ls_lua_pushstring(L, "*");                                /* lanes gen * */

    newTaskScript = malloc( taskscriptlen + 1 );
    strncpy(newTaskScript, taskscript, taskscriptlen);
    newTaskScript[taskscriptlen] = 0;
    ret = ls_luaL_loadstring(L, newTaskScript);            /* lanes gen * script */
    if (ret != 0)
    {
        if (ls_lua_isstring(L, -1))
            printf("jam: Error compiling Lua lane\n%s\n", ls_lua_tostring(L, -1));
        ls_lua_pop(L, 2);
        printf("%s\n", newTaskScript);
        free(newTaskScript);
        return -1;
    }

    free(newTaskScript);
    ret = ls_lua_pcall(L, 2, 1, 0);                        /* lanes lane_h */
    if (ret != 0)
    {
        if (ls_lua_isstring(L, -1))
            printf("jam: Error creating Lua lane\n%s\n", ls_lua_tostring(L, -1));
        ls_lua_pop(L, 2);
        return -1;
    }

    if (!ls_lua_isfunction(L, -1))                            /* lanes lane_h */
    {
        ls_lua_pop(L, 2);
        return -1;
    }

    for (i = 0; i < args->count; ++i)
    {
        LIST* list = lol_get(args, i);
        LISTITEM *l2;
        int index = 0;
        ls_lua_newtable(L);
		for (l2 = list_first(list); l2; l2 = list_next(l2))
		{
			ls_lua_pushstring(L, list_value(l2));
			ls_lua_rawseti(L, -2, ++index);
		}
    }

    ret = ls_lua_pcall(L, args->count, 1, 0);                        /* lanes ret */
    if (ret != 0)
    {
        if (ls_lua_isstring(L, -1))
            printf("jam: Error calling Lua lane\n%s\n", ls_lua_tostring(L, -1));
        ls_lua_pop(L, 2);
        return -1;
    }

    ref = ls_luaL_ref(L, LUA_REGISTRYINDEX);
    ls_lua_pop(L, 1);
    return ref;
}