Ejemplo n.º 1
0
/**
 * Initialize the camscripter API we're exposing to Lua
 */
void init_lua() {
    /* open lua state */
	L=lua_open();
    
    // open lua libraries as needed/wanted (not all can fit on the scripter)
    //luaopen_base(L);
    //luaopen_table(L);
    //luaopen_math(L);
    //luaopen_string(L);
    //luaopen_package(L);
    //luaopen_os(L);
    //luaopen_io(L);
    //luaopen_debug(L);

    // register our functions, constants, and structs
    register_lua_functions();
    register_lua_constants();
    register_image_struct();
    register_framediff_struct();
    register_tracker_struct();
    register_pixel_struct();

    
	// register call back for interrupting LUA execution
	lua_sethook(L, interrupt_lua_exec, LUA_MASKLINE, 0);

    // lessen the pause length to make the lua garbage collector more aggressive
    lua_gc(L, LUA_GCSETPAUSE, 125);  // default is 200
}
Ejemplo n.º 2
0
void lua_init()
{
	g_pLuaVm = lua_open();
	lua_baselibopen(g_pLuaVm);
	lua_tablibopen(g_pLuaVm);
	lua_iolibopen(g_pLuaVm);
	lua_strlibopen(g_pLuaVm);
	lua_mathlibopen(g_pLuaVm);
	register_lua_functions(g_pLuaVm);

	g_pEffectLuaVm = lua_open();
	lua_baselibopen(g_pEffectLuaVm);
	lua_tablibopen(g_pEffectLuaVm);
	lua_iolibopen(g_pEffectLuaVm);
	lua_strlibopen(g_pEffectLuaVm);
	lua_mathlibopen(g_pEffectLuaVm);
	register_lua_functions(g_pEffectLuaVm);
}
Ejemplo n.º 3
0
void context_new_VM(context_t * context)
{
	context_lock_list();
	context->luaVM = lua_open();
	lua_baselibopen(context->luaVM);
	lua_tablibopen(context->luaVM);
	lua_iolibopen(context->luaVM);
	lua_strlibopen(context->luaVM);
	lua_mathlibopen(context->luaVM);

	register_lua_functions(context);
	context_unlock_list();
}
Ejemplo n.º 4
0
Archivo: main.c Proyecto: Kakama/denice
// Main function
int main(int argc, char** argv){
	irc_callbacks_t irc_callbacks;
	char* host_str;
	int host_len, ssl;
	I = 0;
	
	if(argc != 2)
		error(1, "Error: config file must be specified on comand line\n");
	
	// load config from ini
	conf_file = argv[1];
	C = iniparser_load(conf_file);
	
	// parse server config and generate a string to give to libircclient
	ssl = iniparser_getboolean(C, "server:ssl", 0);
	host_len = strlen(iniparser_getstring(C, "server:host", "")) + (ssl ? 1 : 0);
	host_str = malloc(host_len + 1);
	host_str[0] = '#';
	host_str[host_len] = '\0';
	strcpy(&host_str[ssl ? 1 : 0], iniparser_getstring(C, "server:host", ""));
	
	// init local data structures
	mem_init();
	cbtable_init();
		
	// init mysql
	S = mysql_init(NULL);
	if(mysql_real_connect(S,
	      iniparser_getstring(C, "mysql:host", "localhost"),
	      iniparser_getstring(C, "mysql:user", "root"),
	      iniparser_getstring(C, "mysql:pass", ""),
	      iniparser_getstring(C, "mysql:database", ""),
	      iniparser_getint(C, "mysql:port", 0), 0, 0) == NULL) 
	    error(1, "Unable to connect to mysql: %s\n", mysql_error(S));
	
	// init lua
	L = luaL_newstate();
	luaL_openlibs(L);
	register_lua_functions();
	if(luaL_dofile(L, iniparser_getstring(C,"bot:file","/dev/null"))){
		size_t lua_errlen = 0;
		const char* lua_error = luaL_checklstring(L, -1, &lua_errlen);
		error(1, "Error processing Lua script:\n%s\n", lua_error);
	}

	// init libircclient
	memset(&irc_callbacks, 0, sizeof(irc_callbacks));
	irc_callbacks.event_connect = event_generic;
	irc_callbacks.event_nick    = event_generic;
	irc_callbacks.event_quit    = event_generic;
	irc_callbacks.event_join    = event_generic;
	irc_callbacks.event_part    = event_generic;
	irc_callbacks.event_mode    = event_generic;
	irc_callbacks.event_umode   = event_generic;
	irc_callbacks.event_topic   = event_generic;
	irc_callbacks.event_kick    = event_generic;
	irc_callbacks.event_channel = event_command;
	irc_callbacks.event_privmsg = event_command;
	irc_callbacks.event_notice  = event_generic;
	irc_callbacks.event_unknown = event_generic;
	irc_callbacks.event_invite  = event_generic;
	irc_callbacks.event_ctcp_req = event_generic;
	irc_callbacks.event_ctcp_rep = event_generic;
	irc_callbacks.event_ctcp_action = event_generic;
	irc_callbacks.event_channel_notice = event_generic;
	irc_callbacks.event_numeric = event_numeric;
	do_quit = 0;

	while(!do_quit){
		if(I) irc_destroy_session(I);

		I = irc_create_session(&irc_callbacks);
		if(!I)
			error(1, "Unable to create IRC session... probably out of memory\n");
		irc_option_set(I, LIBIRC_OPTION_STRIPNICKS);
		irc_option_set(I, LIBIRC_OPTION_SSL_NO_VERIFY);
		//irc_option_set(I, LIBIRC_OPTION_DEBUG);
		
		// initialize irc server connection
		if(irc_connect(I,
				   host_str,
				   iniparser_getint(C,"server:port",6667), 0,
				   iniparser_getstring(C,"bot:nick","bot"),
				   iniparser_getstring(C,"bot:user","bot"),
				   "libircclient"
				  ))
			irc_error(I,1);
	
		// not sure why we need to sleep here, but if we don't, we can't connect
		sleep(1);
	
		// run the irc client loop
		if(irc_run(I))
		irc_error(I,0);
	}
	
	// clean up
	mysql_close(S);
	irc_destroy_session(I);
	lua_close(L);
	cbtable_destroy();
	iniparser_freedict(C);
	free(host_str);
	return EXIT_SUCCESS;
}