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 Xavier Wang once stated:
> 2011/10/13 Patrick Mc(avery <>:
> > I am planning on changing my business name for the 6th time. In a project I
> > did a while back, I used X as a separator and wrote code like this,
> > someXstupidXvar, I'm really bad at naming things!
> >
> > In my next project I will be heavily using the Lua C API. I like their
> > naming conventions but I want my code to be easy to spot amongst theirs.
> >
> > I figure that most non-trivial names have a commonly used part and one or
> > more uncommon parts.
> >
> > I was thinking of truncating the common part at 3 or 4 characters and
> > capitalizing it, even if it did not sample the syllables of the full name.
> > So STA instead of STK for stack or ARR instead of ARY for array.  I was then
> > thinking of separating with an underscore and then using lowercase and a
> > non-abbreviated name(s) for the less common parts.
> >
> > so here are some fictitious examples
> >
> > ARR_pop
> > ARR_rotate_left
> > STR_concatenate
> > STR_copy
> > NUM_to_hex
> > NUM_double
> >
> > Does this sound logical? Any pitfalls I am setting myself up for? Is this
> > more of my naming insanity?
> >
> > Thanks for reading-Patrick
> >
> >
> >
> In my personal opinion, I think it's ugly :-(.

  Here are the functions name I have for my version of a Lua network API (C
function, then Lua function name):

The following are available via the module:


I used "" to ensure that I don't overload any existing modules
named "net".  I also have modules like "org.conman.table" that contain a few
table related routines I wrote that I found useful, as well as
"org.conman.string", "org.conman.debug" and so on.  

The rest are all bound to a metatable to the userdata returned to Lua. 

	socklua___tostring()	sockvar:__tostring()
	socklua_bind()		sockvar:bind()
	socklua_connect()	sockvar:connect()
	socklua_listen()	sockvar:listen()
	socklua_accept()	sockvar:accept()
	socklua_read()		sockvar:read()
	socklua_write()		sockvar:write()
	socklua_shutdown()	sockvar:shutdown()
	socklua_close()		sockvar:close()
	socklua_fd()		sockvar:fd()
	addrlua___index		addrvar:__index()
	addrlua___tostring	addrvar:__tostring()
	addrlua___eq		addrvar:__eq()
	addrlua___lt		addrvar:__lt()
	addrlua___le		addrvar:__le()
	addrlua___len		addrvar:__len()

(that last function returns the length of the address, 4 for IPv4 addresses,
16 for IPv6)

  I find that naming scheme makes it easy to map the C API to the Lua API.  

  -spc (I found I didn't care for the LuaSocket API, so I ended up writing
	my own)