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 Marc Balmer once stated:
> Hi all
> 
> I have a question of style.  It's about using constants in modules.
> 
> Let's say we have a fictious C library libfoo that defines a preprocessor
> symbol INFO with a value of e.g. 42.
> 
> Then I write a Lua module foo which exposes libfoo's functionality to Lua. 
> Should INFO be an integer constant in foo or rather a string that is
> looked up using luaL_checkoption()?
> 
> i.e.
> 
> foo.somefunc(foo.INFO, 'test data')
> 
> or
> 
> foo.somefunc('info', 'test data')
> 
> It's probably only a question of style or taste, but what is your
> opininion (or remarks) on this?

  I use option 2 quite a bit (such constants marked in 'single quotes'):

https://github.com/spc476/lua-conmanorg/blob/master/src/net.c
	sock = org.conman.net.socket('ip','tcp')
	addr = org.conman.net.address2("www.google.com",'any','tcp','http')

https://github.com/spc476/lua-conmanorg/blob/master/src/syslog.c
	syslog.open("myprogram",'daemon')
	syslog('debug',"frobulator=%d",frobvalue)
	syslog('error',"syserr=%d",error)

https://github.com/spc476/lua-conmanorg/blob/master/src/clock.c
	org.conman.clock.sleep(.25,'monotonic')
	now = org.conman.clock.get('realtime')

  -spc