lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Thomas Harning Jr. wrote:
> Well.. if you want to call functions with the int 
> fn(lua_State*) signature... I think what he means is calling 
> into other libraries, such as opengl/openal/sdl/etc...

In the following example, bar is faster than foo.
/******/
__declspec(dllimport) void glVertex2f(GLfloat x, GLfloat y);
void foo()
{
   glVertex2f(33.f, 47.f);
}

typedef void (*PFN_GL_VERTEX2F)(GLfloat x, GLfloat y);
static PFN_GL_VERTEX2F pfn_glVertex2f = NULL;

void init()
{
   HMODULE lib = LoadLibrary("opengl32");
   if (lib)
      pfn_glVertex2f = GetprocAddress(lib, "glVertex2f");
}

void bar()
{
   if (pfn_glVertex2f)
      (*pfn_glVertex2f)(33.f, 47.f);
   else
      /* Whatever error handling you use */ exit(1);
}
/******/