lua-users home
lua-l archive

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


I'm trying to make a binding of the Lua C API with a language called
Lisaac. And doing that I found there is a problem to create a binding
for lua_atpanic function because the function pointer given can't be a
closure (and that's a problem for me)

... Now, let me explain a little the language ...

Lisaac is an object oriented programming language based on prototypes
rather than classes. That is instead of having classes and instantiate
them, we have already living objects and we clone them.

The syntax is inherited from Smalltalk and the language itself is I
think related to Eiffel (the Lisaac compiler was written in Eiffel
before being bootstrapped). Like Eiffel the compiler creates optimized
C code but unlike Eiffel, there is a direct access to the C code within
the language. For example anything written between back-quotes (`) is
directly inserted in the C code.

Like smalltalk, Lisaac doesn't have control structure (if, loops, ...)
and everything is message. For example if is a message we send to a
BOOLEAN object. And as argument, we give a BLOCK object (which is just
a closure).

For example we could write something like (just to give you and idea
of what's possible) :

	Section Header

	  - name := LUA_TEST;

	Section Public

	  - main <- // the main slot/method: entry point
	    + lua :LUA_STATE;
	    + pointer :POINTER;
	    lua := LUA_STATE.create;
	    // test some C code
	    pointer := lua.pointer;
	    // add a function and call it
	    lua.pushcfunction { lua:LUA_STATE;
	      "testing C functions\n".print;
	      lua.pushstring "return value";
	      1 // return value of the BLOCK. Tell Lua there is 1 result
	        // Notice there is no semicolon after `1'
	    lua.call_multret 0;
	    // load a file
	    lua.loadfile "test.lua";

There you see that we can easily register a function. Everything that
is between {} is in fact a closure and is not evaluated directly.

... so now let me explain my problem ...

How did I implemented pushcfunction ?

I created a prototype called LUA_CFUNCTION that is cloned each time I
need to register a C function and which contain a slot (property) that
contains the BLOCK that is given to pushcfunction.

Then I heed to get a pointer to a C function to give it to the
lua_pushcfunction function. In Lisaac it is not (yet ?) possible to get
a pointer from a slot of a specific object. What I had to do is to
write a C closure that has as upvalue a pointer to the Lisaac object
that holds my BLOCK that contains the actual body of the function.

If I can't have upvalues to my C function, I can't find the object to
call. And that's exactly what happens with lua_atpanic.

... so ...

What I am asking ... it is possible to have nevertheless an upvalue
with the panic function or is it hopeless ? If it is, can I ask the Lua
developers if they can consider this issue for the next Lua release.

For example the lua_cpcall function takes a void* pointer as argument
and put it in the first upvalue.


For those who are interested in the Lisaac language, the homepage is
<>. The language is near version 0.2 but is not yet
available. It will be open source. My work with the Lua binding is
available for anyone who ask me with the same licence as Lua itself


Mildred       <> <>
Clef GPG :    <hkp://> ou <>
Fingerprint : 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 [9A7D 2E2B]