Esempio n. 1
0
int main(int argc, char *argv[])
{
        int version;
	void *thread_result;
	long status;
        pthread_t repl_thread_id;
        pthread_t web_thread_id;
        pthread_mutex_t main_mutex = PTHREAD_MUTEX_INITIALIZER;
        lua_State *L_main;

        /*
         * Set up lua state with data at specified version
         */
        if (argc < 2) {
                printf("Usage: qplan <version>\n");
                return 1;
        }
        version = strtol(argv[1], NULL, 0);
        L_main = init_lua_state(version);


        /*
         * Set up context and spin up threads
         */
        QPlanContext qplan_context;
        qplan_context.main_lua_state = L_main;
        qplan_context.main_mutex = &main_mutex;

	/* Create REPL thread */
	status = pthread_create(&repl_thread_id, NULL, repl_routine, (void *)&qplan_context);
	if (status != 0)
		err_abort(status, "Create repl thread");

        /* Create web server thread */
	status = pthread_create(&web_thread_id, NULL, web_routine, (void *)&qplan_context);
	if (status != 0)
		err_abort(status, "Create web thread");
	status = pthread_detach(web_thread_id);
	if (status != 0)
		err_abort(status, "Problem detaching web thread");


	/* Join REPL thread */
	status = pthread_join(repl_thread_id, &thread_result);
	if (status != 0)
		err_abort(status, "Join thread");

        /*
         * Clean up
         */
        lua_close(L_main);
	printf("We are most successfully done!\n");
	return 0;
}
Esempio n. 2
0
void
init_lua_binding(){
	config_t *cfg;
	cfg = get_config();

	init_lua_state(cfg->master_lua_file,
			cfg->master_lua_path,
			cfg->master_lua_cpath);

	reg_function("message_gate",_message_gate);
	reg_function("message_worker",_message_worker);
	reg_function("message_all_gate",_message_all_gate);
	reg_function("message_all_worker",_message_all_worker);
}
Esempio n. 3
0
static int luablock_init(ubx_block_t *b)
{
	char *lua_file, *lua_str;
	unsigned int lua_file_len, lua_str_len;

	int ret = -EOUTOFMEM;
	struct luablock_info* inf;

	if((inf = calloc(1, sizeof(struct luablock_info)))==NULL)
		goto out;

	b->private_data = inf;

	lua_file = (char *) ubx_config_get_data_ptr(b, "lua_file", &lua_file_len);
	lua_file = (!strncmp(lua_file, "", lua_file_len)) ? NULL : lua_file;

	lua_str = (char *) ubx_config_get_data_ptr(b, "lua_str", &lua_str_len);
	lua_str = (!strncmp(lua_str, "", lua_str_len)) ? NULL : lua_str;

	if((inf->exec_str_buff = ubx_data_alloc(b->ni, "char", EXEC_STR_BUFF_SIZE)) == NULL) {
		ERR("failed to allocate exec_str buffer");
		goto out_free1;
	}

	if(init_lua_state(inf, lua_file, lua_str) != 0)
		goto out_free2;

	if((ret=call_hook(b, "init", 0, 1)) != 0)
		goto out_free2;

	/* Ok! */
	ret = 0;
	goto out;

 out_free2:
	free(inf->exec_str_buff);
 out_free1:
	free(inf);
 out:
	return ret;
}