Bugfixes

First thanks for providing this binding for openGL ;)
However I found it troublesome to use this lib due to weird crashes. I finally found the glitch which is located in get_array2f. The function is not balancing the lua VM stack. I fixed the loop that caused a stackoverflow that lead to a crash somewhat later (thus hard to track down the error).
for(i = 0; i < n; i++)
{
lua_rawgeti(L, index, i+1);
if(!lua_istable(L, -1)) {
lua_pop(L,1); // undo the change to the stack, normally not necessary
return -1;
}
for(j = 0; j < *size; j++)
{
lua_rawgeti(L, -1, j + 1);
(*array)[i*(*size) + j] = (GLfloat)lua_tonumber(L, -1);
lua_pop(L, 1); // lua_remove(L,-1) equivalent
}
lua_pop(L,1); // pop the row off
}
I also saw during examination that there is a memory leak in the texture function gl_tex_image.
The function returned without freeing the pixels array, i.e.
if((height = get_array2f(L, 4, &pixels, &width)) != -1)
{
glTexImage2D(GL_TEXTURE_2D, (GLint)lua_tonumber(L, 1),
iformat, width/iformat, height, 0, e, GL_FLOAT, pixels);
free(pixels); // I added this line
return 0;
}
In other places existed the same glitch.
—zet