lua-users home
lua-l archive

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


It was thus said that the Great Daurnimator once stated:
> 
> If we *do* want to talk about standardisation, I'd like to take it in
> the direction of common OS data structures being portable between
> libraries (to pick on an example of mine from another thread:
> sigset_t).

  It being this message, http://lua-users.org/lists/lua-l/2015-09/msg00331.html,
right?  I'm looking over my own code in org.conman, and I have the following
types:

	sigset_t
	DIR*
	pollset__t
	struct sockaddr
	int

sigset_t, DIR* and struct sockaddr are pretty straightforward (although in
my case, I have struct sockaddr, struct sockaddr_in, struct sockaddr_in6 and
struct sockaddr_un as a union).  The pollset__t is my own invention and
hides the implementation of select()---on Linux, I actually use
epoll_wait(), and for other Unix systems, poll() (and I do have a version
based on select(), but only to be complete).  The lone 'int' is wrapped for
socket handling.

But then you said:

> The key thing I counted on is that we have the same **ABI** per registry
> key. i.e. that `sigset_t *set = luaL_checkmeta(L, n, "sigset_t")` will
> always result in a valid sigset_t pointer.

  First, I'm not sure if doing

	sigset_t *set = luaL_checkmeta(L,n,"sigset_t");

buys you much; I can only think of contrived circumstances where you have
two different libraries providing signal sets where that would be an issue. 
Now, by ABI, do you also mean metamethods?  Because, oh boy, do I have
metamethods.  Just as an example, for signal sets, I have:

	__tostring
	__index		check if a signal is in a set
	__newindex	add (or remove) a signal to a set
	__add		union two signal sets
	__sub		intersect to signal sets
	__unm		flip signal set

  The pollset__t is interesting---the methods are the same despite the
implementation:

	__tostring
	__gc
	insert		insert a file handle (and optional Lua value)
	update		update the trigger for a given file handle
	remove		remove a file handle from the set
	events		a list of all file events since the previous call

  -spc (Examples can be provided upon request)