Exemple #1
0
/* add_job(string/table output, string label, string command, ...) */
int lf_add_job(lua_State *L)
{
	struct JOB *job;
	struct CONTEXT *context;
	
	if(lua_gettop(L) < 3)
		luaL_error(L, "add_job: too few arguments");

	/*luaL_checktype(L, 1, LUA_TSTRING); */
	luaL_checktype(L, 2, LUA_TSTRING);
	luaL_checktype(L, 3, LUA_TSTRING);
	
	/* fetch contexst from lua */
	context = context_get_pointer(L);

	/* create the job */
	job = node_job_create(context->graph, lua_tostring(L,2), lua_tostring(L,3));

	/* create the nodes */
	deep_walk(L, 1, 1, callback_addjob_node, job);

	/* seek deps */
	deep_walk(L, 4, lua_gettop(L), callback_addjob_deps, job);

	return 0;
}
Exemple #2
0
int lf_add_dependency_cpp(lua_State *L)
{
	struct CONTEXT *context;
	struct DEFERRED *deferred;
	struct NODE * node;
	int n = lua_gettop(L);
	
	if(n != 1)
		luaL_error(L, "add_dependency_cpp: incorrect number of arguments");
	luaL_checkstring(L,1);
	
	context = context_get_pointer(L);
	node = node_find(context->graph, lua_tostring(L,1));

	if(!node)
		luaL_error(L, "add_dependency_cpp: couldn't find node with name '%s'", lua_tostring(L,1));

	deferred = (struct DEFERRED *)mem_allocate(context->deferredheap, sizeof(struct DEFERRED));
	deferred->node = node;
	deferred->user = current_includepaths;
	deferred->run = dependency_cpp_do_run;
	deferred->next = context->firstdeferred_cpp;
	context->firstdeferred_cpp = deferred;
	return 0;
}
Exemple #3
0
/* add_output(string output, string other_output) */
int lf_add_output(lua_State *L)
{
	struct NODE *output;
	struct NODE *other_output;
	struct CONTEXT *context;
	int i;
	const char *filename;
	
	if(lua_gettop(L) != 2)
		luaL_error(L, "add_output: incorrect number of arguments");

	luaL_checktype(L, 1, LUA_TSTRING);
	luaL_checktype(L, 2, LUA_TSTRING);
	
	context = context_get_pointer(L);

	output = node_find(context->graph, lua_tostring(L,1));
	if(!output)
		luaL_error(L, "add_output: couldn't find node with name '%s'", lua_tostring(L,1));

	if(!output->job->real)
		luaL_error(L, "add_output: '%s' does not have a job", lua_tostring(L,1));


	filename = lua_tostring(L, -1);
	i = node_create(&other_output, context->graph, filename, output->job);
	if(i == NODECREATE_NOTNICE)
		luaL_error(L, "add_output: node '%s' is not nice", filename);
	else if(i == NODECREATE_EXISTS)
		luaL_error(L, "add_output: node '%s' already exists", filename);
	else if(i != NODECREATE_OK)
		luaL_error(L, "add_output: unknown error creating node '%s'", filename);

	return 0;
}
Exemple #4
0
/* add_pseudo(string node) */
int lf_add_pseudo(lua_State *L)
{
	struct NODE *node;
	struct CONTEXT *context;
	int i;
	
	if(lua_gettop(L) != 1)
		luaL_error(L, "add_pseudo: incorrect number of arguments");

	luaL_checktype(L, 1, LUA_TSTRING);
	
	/* fetch contexst from lua */
	context = context_get_pointer(L);

	/* create the node */
	i = node_create(&node, context->graph, lua_tostring(L,1), NULL);
	if(i == NODECREATE_NOTNICE)
		luaL_error(L, "add_pseudo: node '%s' is not nice", lua_tostring(L,1));
	else if(i == NODECREATE_EXISTS)
		luaL_error(L, "add_pseudo: node '%s' already exists", lua_tostring(L,1));
	else if(i != NODECREATE_OK)
		luaL_error(L, "add_pseudo: unknown error creating node '%s'", lua_tostring(L,1));
		
	node_set_pseudo(node);
	return 0;
}
Exemple #5
0
int lf_add_dependency_cpp_set_paths(lua_State *L)
{
	struct CONTEXT *context;
	int n = lua_gettop(L);
	
	if(n != 1)
		luaL_error(L, "add_dependency_cpp_set_paths: incorrect number of arguments");
	luaL_checktype(L, 1, LUA_TTABLE);
	
	context = context_get_pointer(L);
	current_includepaths = NULL;
	build_stringlist(L, context->deferredheap, &current_includepaths, 1);
	return 0;
}
Exemple #6
0
/* nodeexist(string nodename) */
int lf_nodeexist(struct lua_State *L)
{
	struct NODE *node;
	
	if(lua_gettop(L) != 1)
		luaL_error(L, "nodeexists: takes exactly one argument");

	luaL_checktype(L, 1, LUA_TSTRING);
	
	node = node_find(context_get_pointer(L)->graph, lua_tostring(L,1));
	if(!node)
		lua_pushboolean(L, 1);
	else
		lua_pushboolean(L, 0);
	return 1;
}
Exemple #7
0
/* update_globalstamp(string filename) */
int lf_update_globalstamp(lua_State *L)
{
	struct CONTEXT *context;
	time_t file_stamp;
	
	if(lua_gettop(L) < 1)
		luaL_error(L, "update_globalstamp: too few arguments");
	luaL_checktype(L, 1, LUA_TSTRING);

	context = context_get_pointer(L);
	file_stamp = file_timestamp(lua_tostring(L,1)); /* update global timestamp */
	
	if(file_stamp > context->globaltimestamp)
		context->globaltimestamp = file_stamp;
	
	return 0;
}
Exemple #8
0
static void callback_addjob_node(lua_State *L, void *user)
{
	struct JOB *job = (struct JOB *)user;
	struct CONTEXT *context = context_get_pointer(L);
	struct NODE *node;
	const char *filename;
	int i;

	luaL_checktype(L, -1, LUA_TSTRING);
	filename = lua_tostring(L, -1);

	i = node_create(&node, context->graph, filename, job);
	if(i == NODECREATE_NOTNICE)
		luaL_error(L, "add_job: node '%s' is not nice", filename);
	else if(i == NODECREATE_EXISTS)
		luaL_error(L, "add_job: node '%s' already exists", filename);
	else if(i != NODECREATE_OK)
		luaL_error(L, "add_job: unknown error creating node '%s'", filename);
}
Exemple #9
0
/* default_target(string filename) */
int lf_default_target(lua_State *L)
{
	struct NODE *node;
	struct CONTEXT *context;

	int n = lua_gettop(L);
	if(n != 1)
		luaL_error(L, "default_target: incorrect number of arguments");
	luaL_checktype(L, 1, LUA_TSTRING);

	/* fetch context from lua */
	context = context_get_pointer(L);

	/* search for the node */
	node = node_find(context->graph, lua_tostring(L,1));
	if(!node)
		luaL_error(L, "default_target: node '%s' not found", lua_tostring(L,1));
	
	/* set target */
	context_default_target(context, node);
	return 0;
}
Exemple #10
0
int lf_set_filter(struct lua_State *L)
{
	struct NODE *node;
	const char *str;
	size_t len;
	
	/* check the arguments */
	if(lua_gettop(L) < 2)
		luaL_error(L, "set_filter: too few arguments");
		
	luaL_checktype(L, 1, LUA_TSTRING);
	luaL_checktype(L, 2, LUA_TSTRING);

	/* find the node */
	node = node_find(context_get_pointer(L)->graph, lua_tostring(L,1));
	if(!node)
		luaL_error(L, "set_filter: couldn't find node with name '%s'", lua_tostring(L,1));

	/* setup the string */	
	str = lua_tolstring(L, 2, &len);
	node->job->filter = (char *)mem_allocate(node->graph->heap, len+1);
	memcpy(node->job->filter, str, len+1);
	return 0;
}
Exemple #11
0
/* add_dependency(string node, string dependency) */
static int add_node_attribute(lua_State *L, const char *funcname, struct NODE *(*callback)(struct NODE*, const char *))
{
	struct NODE *node;
	struct CONTEXT *context;
	int n = lua_gettop(L);
	struct NODEATTRIB_CBINFO cbinfo;
	
	if(n < 2)
		luaL_error(L, "%s: to few arguments", funcname);

	luaL_checktype(L, 1, LUA_TSTRING);

	context = context_get_pointer(L);

	node = node_find(context->graph, lua_tostring(L,1));
	if(!node)
		luaL_error(L, "%s: couldn't find node with name '%s'", funcname, lua_tostring(L,1));
	
	/* seek deps */
	cbinfo.node = node;
	cbinfo.callback = callback;
	deep_walk(L, 2, n, callback_node_attrib, &cbinfo);
	return 0;
}