Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
static int pmain (ls_lua_State *L)
{
    int top;
    int ret;

    ls_luaL_openlibs(L);

    ls_lua_pushcclosure(L, LS_jam_getvar, 0);
    ls_lua_setfield(L, LUA_GLOBALSINDEX, "jam_getvar");
    ls_lua_pushcclosure(L, LS_jam_setvar, 0);
    ls_lua_setfield(L, LUA_GLOBALSINDEX, "jam_setvar");
    ls_lua_pushcclosure(L, LS_jam_evaluaterule, 0);
    ls_lua_setfield(L, LUA_GLOBALSINDEX, "jam_evaluaterule");

    top = ls_lua_gettop(L);
    ret = ls_luaL_loadstring(L, "require 'lanes'");
    ls_lua_callhelper(top, ret);
    return 0;
}
Ejemplo n.º 3
0
static int pmain (ls_lua_State *L)
{
    int top;
    int ret;

    ls_luaL_openlibs(L);

    ls_lua_pushcclosure(L, LS_jam_getvar, 0);
    ls_lua_setglobal(L, "jam_getvar");
    ls_lua_pushcclosure(L, LS_jam_setvar, 0);
    ls_lua_setglobal(L, "jam_setvar");
    ls_lua_pushcclosure(L, LS_jam_action, 0);
    ls_lua_setglobal(L, "jam_action");
    ls_lua_pushcclosure(L, LS_jam_evaluaterule, 0);
    ls_lua_setglobal(L, "jam_evaluaterule");
    ls_lua_pushcclosure(L, LS_jam_expand, 0);
    ls_lua_setglobal(L, "jam_expand");
    ls_lua_pushcclosure(L, LS_jam_parse, 0);
    ls_lua_setglobal(L, "jam_parse");
    ls_lua_pushcclosure(L, LS_jam_print, 0);
    ls_lua_setglobal(L, "jam_print");

    top = ls_lua_gettop(L);
    ret = ls_luaL_loadstring(L, "lanes = require 'lanes'");
    ls_lua_callhelper(top, ret);

    ls_lua_getglobal(L, "lanes");                       /* lanes */
    ls_lua_getfield(L, -1, "configure");                /* lanes configure */
    ls_lua_newtable(L);                                 /* lanes configure table */
    ls_lua_pushcclosure(L, lanes_on_state_create, 0);   /* lanes configure table lanes_on_state_create */
    ls_lua_setfield(L, -2, "on_state_create");          /* lanes configure table */
    ret = ls_lua_pcall(L, 1, 0, 0);                     /* lanes */
    if (ret != 0) {
        const char* err = ls_lua_tostring(L, -1);  (void)err;
	}
    ls_lua_pop(L, 2);

    ls_lua_newtable(L);
    ls_lua_setglobal(L, "LineFilters");

    return 0;
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
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;
}