[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: One more thing about Io and Lua comparison
- From: Steve Dekorte <steve@...>
- Date: Sat, 19 Apr 2003 14:45:08 -0700
On Saturday, April 19, 2003, at 02:09 PM, Ignacio Castaño wrote:
Lua binding interface is a very low level API. I haven't used Io's
bindings,
but I've heard that they are very easy to use. Io is a language made
by a
single person and with a small comunity, and I belive that it has more
external libraries available than Lua. Maybe Steve can clarify this
better
than me.
Hi Ignacio,
Sure. Here's what a binding for a GL function looks like:
--- Io
--------------------------------------------------------------------
IoValue *IoGL_glVertex3d(IoGL *self, IoValue *locals, IoMessage *m)
{
IoNumber *x = IoMessage_locals_numberArgAt_(m, locals, 0);
IoNumber *y = IoMessage_locals_numberArgAt_(m, locals, 1);
IoNumber *z = IoMessage_locals_numberArgAt_(m, locals, 2);
glVertex3d(
(GLdouble)IoNumber_asDouble(x),
(GLdouble)IoNumber_asDouble(y),
(GLdouble)IoNumber_asDouble(z));
return (IoValue *)self;
}
...
Hash_at_put_(m, IOSTRING("glVertex3d"), IOCFUNCTION(IoGL_glVertex3d));
--- Lua
--------------------------------------------------------------------
static int toluaI_gl_glVertex3d00(lua_State* tolua_S)
{
if (
!tolua_istype(tolua_S,1,LUA_TNUMBER,0) ||
!tolua_istype(tolua_S,2,LUA_TNUMBER,0) ||
!tolua_istype(tolua_S,3,LUA_TNUMBER,0) ||
!tolua_isnoobj(tolua_S,4)
)
goto tolua_lerror;
else
{
GLdouble x = ((GLdouble) tolua_getnumber(tolua_S,1,0));
GLdouble y = ((GLdouble) tolua_getnumber(tolua_S,2,0));
GLdouble z = ((GLdouble) tolua_getnumber(tolua_S,3,0));
{
glVertex3d(x,y,z);
}
}
return 0;
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'glVertex3d'.");
return 0;
}
...
tolua_function(tolua_S,NULL,"glVertex3d",toluaI_gl_glVertex3d00);
-------------------------------------------------------------------
Very similar. The big difference is that Io's bindings are OO - that
is, the glVertex3d() function is a method on an OpenGL object which
internally holds any related state. In Lua, you add functions to Lua
and custom userdata to hold any state associated with a binding which
needs to be passed in with each call. (this example doesn't show that
though as GL has static variables to hold it's state) Also, with Io
bindings there's no stack that needs to be maintained. Arguments you
don't use are ignored and the return argument is passed back in the
normal way.
Cheers,
Steve
OSX freeware and shareware: http://www.dekorte.com/downloads.html