示例#1
0
文件: graph.c 项目: Algateras/GraphX
void waitgraph(void)
{
    XEvent report;

    CHECKINIT(waitgraph);

/*    XGetWindowAttributes(display,window,&wattr);
    XCopyArea(display, shadow, window, gc, 
                 0, 0, wattr.width, wattr.height, 0, 0);
*/

    XSelectInput(display, window, KeyPressMask | ExposureMask);
    do {
        XNextEvent(display, &report);
        switch (report.type) {
        case Expose:
            /* Unless this is the last contiguous expose,
               don't draw the window (sic.) */
            if (report.xexpose.count != 0)
                break;
            /* On dessine la fenêtre */
/*            XCopyArea(display, shadow, window, gc, 
                     0, 0, wattr.width, wattr.height, 0, 0);
*/            /* fprintf(stderr, "%s: ne peut redessiner la fenêtre...\n", NAME); */
            break;
        case KeyPress:
            return;
        default:
            break;
        }
    } while (1);
}
示例#2
0
void initCompileEnv()
{
	CHECKINIT(env);
	env=malloc(sizeof(CompileEnv));

	if(access("/usr/bin/gcc", X_OK) == -1)
		writeLog(WARNING, "to use c script (*.c scripts), install 'gcc'");
	else
		env->gcc=true;

	const Config *config=getConfig();
	assert(config->tmp_dir!=NULL);

	// Create tmp folder if doesn't exist
	if (access(config->tmp_dir, R_OK | W_OK) == -1)
	{
		if(mkdir(config->tmp_dir, 0770) == -1)
			die("echec of mkdir %s", config->tmp_dir);
	}
	DIR *tmp=opendir(config->tmp_dir);
	if (tmp == NULL)
		die("opendir error");
	PRINT("tmpdir : %s", config->tmp_dir);
PRINT("%s", strerror(errno));
	closedir(tmp);

	// Compile all the file in the folder
	compileFolder(config);
}
示例#3
0
int io_toChar(lua_State *L)
{
	CHECKINIT(tinit, L);

	lua_pushinteger(L, *((const io8t *) luaL_checkstring(L, 1)));

	return 1;
}
示例#4
0
int io_fromChar(lua_State *L)
{
	io8t integer;

	CHECKINIT(tinit, L);

	integer = (io8t) luaL_checkinteger(L, 1);

	lua_pushlstring(L, ((const char *) &integer), sizeof(integer));

	return 1;
}
示例#5
0
文件: graph.c 项目: Algateras/GraphX
void cleargraph(void)
{
    XWindowAttributes wattr;

    CHECKINIT(cleargraph);

	XGetWindowAttributes(display,window,&wattr);

	XSetForeground(display, gc, white);
	XFillRectangle(display,shadow,gc,0,0,wattr.width, wattr.height);
	XSetForeground(display, gc, black);

/*	XClearWindow( display, window ); */
}
示例#6
0
int io_getShort(lua_State *L)
{
	int c;
	io16t integer;
	FILE *fin = *((FILE **)lua_touserdata(L, -1));

	CHECKINIT(tinit, L);

	if(!fin)
	{
		lua_pushstring(L, "no or invalid file handle passed\n");
		lua_error(L);
	}

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	integer.bytes[1] = (unsigned char) c;
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	integer.bytes[0] = (unsigned char) c;
#else
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	integer.bytes[0] = (unsigned char) c;
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	integer.bytes[1] = (unsigned char) c;
#endif
	lua_pushinteger(L, integer.integer);

	return 1;
}
示例#7
0
int io_fromShort(lua_State *L)
{
	io16t integer;

	CHECKINIT(tinit, L);

	integer.integer = (io32tv) luaL_checkinteger(L, 1);

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
	CHARSWAP(integer_[0], integer_[1]);
#endif

	lua_pushlstring(L, ((const char *) &integer), sizeof(integer));

	return 1;
}
示例#8
0
文件: graph.c 项目: Algateras/GraphX
void closegraph()
{
    CHECKINIT(closegraph);

    XUnmapWindow(display, window);
    XDestroyWindow(display, window);
 	XFreePixmap(display,shadow);
// 	XFreePixmap(display,icon_pixmap);
    XFree(wm_hints);
    XFree(size_hints);
    XFreeGC(display, gc);
//    XUnloadFont( display, font );
    XCloseDisplay(display);

    init = 0;    
    return;
}
示例#9
0
int io_fromFloat(lua_State *L)
{
	io32t number;

	CHECKINIT(tinit, L);

	number.value = (io32ft) luaL_checknumber(L, 1);

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
	CHARSWAP(number.bytes[0], number.bytes[3]);
	CHARSWAP(number.bytes[1], number.bytes[2]);
#endif

	lua_pushlstring(L, ((const char *) &number), sizeof(number));

	return 1;
}
示例#10
0
int io_toShort(lua_State *L)
{
	io16t integer;

	CHECKINIT(tinit, L);

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
	integer.integer = ((const io16t *) luaL_checkstring(L, 1))->integer;
	CHARSWAP(integer.bytes[0], integer.bytes[1]);
#else
	integer.integer = ((const io16t *) luaL_checkstring(L, 1))->integer;
#endif

	lua_pushinteger(L, integer.integer);

	return 1;
}
示例#11
0
int io_toFloat(lua_State *L)
{
	io32t number;

	CHECKINIT(tinit, L);

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
	number.value = ((const io32t *) luaL_checkstring(L, 1))->value;
	CHARSWAP(integer.bytes[0], integer.bytes[3]);
	CHARSWAP(integer.bytes[1], integer.bytes[2]);
#else
	number.value = ((const io32t *) luaL_checkstring(L, 1))->value;
#endif

	lua_pushnumber(L, number.value);

	return 1;
}
示例#12
0
int r_initialize(lua_State *L)
{
	CHECKINIT(tinit, L);

/*
	int stereo  = config_get_d(CONFIG_STEREO)      ? 1 : 0;
	int stencil = config_get_d(CONFIG_REFLECTION)  ? 1 : 0;
	int buffers = config_get_d(CONFIG_MULTISAMPLE) ? 1 : 0;
	int samples = config_get_d(CONFIG_MULTISAMPLE);
	int vsync   = config_get_d(CONFIG_VSYNC)       ? 1 : 0;
	SDL_GL_SetAttribute(SDL_GL_STEREO,             stereo);
	SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,       stencil);
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, buffers);
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, samples);
	SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL,       vsync);
*/

	SDL_GL_SetAttribute(SDL_GL_RED_SIZE,     5);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,   5);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,    5);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,  16);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 16);

	if(TTF_Init() == -1)
	{
		tstr *message = CDLL_FUNCTION("libtstr", "tstr_new", tstr *(*)(void))
			();
		CDLL_FUNCTION("libtstr", "tstr_base_set", void(*)(tstr *, const char *))
			(message, "Error initializing SDL_ttf: ");
		CDLL_FUNCTION("libtstr", "tstr_cat", void(*)(tstr *, const char *))
			(message, TTF_GetError());
		CDLL_FUNCTION("libtstr", "tstr_base_cat", void(*)(tstr *, const char *))
			(message, "\n");
		lua_pushstring(L, CDLL_FUNCTION("libtstr", "tstr_cstr", const char *(*)(tstr *))
							(message));
		CDLL_FUNCTION("libtstr", "tstr_free", void(*)(tstr *))
			(message);
		lua_error(L);
	}
示例#13
0
文件: graph.c 项目: Algateras/GraphX
unsigned long newcolor(float rouge, float vert, float bleu)
{
    XColor color;
    unsigned long fgcolor;

    CHECKINIT(setcolor);

    color.red = rouge * 65535;
    color.green = vert * 65535;
    color.blue = bleu * 65535;

    if (XAllocColor(display, DefaultColormap(display, screen), &color))
        fgcolor = color.pixel;
    else {
        fprintf(stderr, "graph: ne peut allouer la couleur (%f,%f,%f)\n", 
                rouge, vert, bleu);
        fgcolor = black;
    }
    XSetForeground(display, gc, fgcolor);
    
    return fgcolor;
}
示例#14
0
int io_getStr(lua_State *L)
{
	static io8t string[BUFSIZE];
	int i = 0;
	int c;
	FILE *fin = *((FILE **)lua_touserdata(L, -1));

	CHECKINIT(tinit, L);

	if(!fin)
	{
		lua_pushstring(L, "no or invalid file handle passed\n");
		lua_error(L);
	}

	while(i < BUFSIZE && (string[i++] = fgetc(fin)) > 0)
	{
		c = fgetc(fin);
#if EOF <= 0
		if(c <= 0) /* NULL bytes terminate */
#else
		if(c == 0x00 || string[i] == EOF)
#endif
			break;

		string[i++] = c;
	}
	if(i > 0 && string[i - 1] == EOF)
	{
		lua_pushboolean(L, false);

		return 1;
	}

	lua_pushlstring(L, (char *) string, i);

	return 1;
}
示例#15
0
int io_getStrL(lua_State *L)
{
	int c;
	unsigned char *result;
	int i, len = luaL_checkinteger(L, -1);
	FILE *fin = *((FILE **)lua_touserdata(L, -2));

	CHECKINIT(tinit, L);

	if(!fin)
	{
		lua_pushstring(L, "no or invalid file handle passed\n");
		lua_error(L);
	}

	result = malloc(len);

	for(i = 0; i < len; i++)
	{
		c = fgetc(fin);
		result[i] = (unsigned char) c;
		if(c == EOF)
		{
			free(result);

			lua_pushboolean(L, false);

			return 1;
		}
	}

	lua_pushlstring(L, (char *) result, len);

	free(result);

	return 1;
}
示例#16
0
int io_getHomeDirectory(lua_State *L)
{
	const char *userdir;

	CHECKINIT(tinit, L);

#ifdef _WIN32
	userdir = getenv("APPDATA");
#else
	userdir = getenv("HOME");
#endif

	if(userdir)
	{
		lua_pushstring(L, userdir);
		return 1;
	}
	else
	{
		lua_pushnil(L);
		lua_pushstring(L, "error accessing user directory");
		return 2;
	}
}
示例#17
0
int io_getDouble(lua_State *L)
{
	int c;
	io64t number;
	FILE *fin = *((FILE **)lua_touserdata(L, -1));

	CHECKINIT(tinit, L);

	if(!fin)
	{
		lua_pushstring(L, "no or invalid file handle passed\n");
		lua_error(L);
	}

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	number.bytes[7] = (unsigned char) c;
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	number.bytes[6] = (unsigned char) c;
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	number.bytes[5] = (unsigned char) c;
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	number.bytes[4] = (unsigned char) c;
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	number.bytes[3] = (unsigned char) c;
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	number.bytes[2] = (unsigned char) c;
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	number.bytes[1] = (unsigned char) c;
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	number.bytes[0] = (unsigned char) c;
#else
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	number.bytes[0] = (unsigned char) c;
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	number.bytes[1] = (unsigned char) c;
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	number.bytes[2] = (unsigned char) c;
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	number.bytes[3] = (unsigned char) c;
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	number.bytes[4] = (unsigned char) c;
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	number.bytes[5] = (unsigned char) c;
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	number.bytes[6] = (unsigned char) c;
	c = fgetc(fin);
	if(c == EOF)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	number.bytes[7] = (unsigned char) c;
#endif
	lua_pushnumber(L, number.value);

	return 1;
}
示例#18
0
文件: graph.c 项目: Algateras/GraphX
void flushgraph(void)
{
    CHECKINIT(flushgraph);

    XFlush(display);
}
示例#19
0
文件: graph.c 项目: Algateras/GraphX
void putpixel(int x, int y)
{
    CHECKINIT(putpixel);

    XDrawPoint(display, shadow, gc, x, y);
}
示例#20
0
文件: graph.c 项目: Algateras/GraphX
void line(int x1, int y1, int x2, int y2)
{
    CHECKINIT(line);

    XDrawLine(display, shadow, gc, x1, y1, x2, y2);
}