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 Sir Pogsalot once stated:
> I've felt a bit ridiculous trying to mirror some of the C structs when
> "exporting" them to Lua as tables, but I wanted people to be able to follow
> along with a C socket tutorial and expect the same member fields.  

  I've explicitely rejected trying to slavisly follow a C API when writing a
wrapper for Lua, because if I wanted to write in C, I'd write in C.  I want
to write Lua in Lua, if that makes any sense.  And thus, I try to adapt a
Lua interface to be more Luaish, or, at least what makes it easier for *me*
to write Lua code.

  As an example, I could have just wrapped setrlimit() [1]

	process.setrlimit(process.RLIMIT_CPU,{ rlim_cur = 4 , rlim_max = 4})

but like I said, if I wanted C, I have C.  Instead, I spent the time writing
the interface so I could do:

	process.limits.soft.cpu = 4

  Yes, behind the scenes, it calls setrlimit(), but I don't have to both
with that in Lua.  In fact, I can also do:

	print(process.limits.soft.cpu) -- call getrlimit()

> Mostly I've been kept up nights about the tables I return from my
> getaddrinfo(). I really have to keep myself from molding it into a
> friendlier table, but why I am unhappy with luasocket is because I have so
> much trouble figuring out what to expect from its functions.  The
> documentation only goes so far...

  Why are you afraid of molding the results of getaddrinfo() into something
friendlier (or easier)?  Is it because you want people using a C tutorial
for networking to follow along in Lua?  To me, that seems rather odd.  I
just went ahead and made the results in Lua friendlier for my own usage.  My
own interface [2] is called thusly:

	results = net.address2('','any','tcp','www')
	for i = 1 , #results do print(results[i]) end

	> ip:
	> ip:
	> ip:
	> ip:
	> ip:
	> ip6:[2607:f8b0:4008:801::]:80

  Also, the results have already been converted into struct sockaddr so they
can be used directly by socket:connect().

> check out my monstrocity:

  It's perhaps a bit shorter than what I wrote [2] so I don't consider it
that monstrous.  But we might be operating under different definitions of

  -spc (Embrace Lua; if you want C, you know where to find it ... )