lua-users home
lua-l archive

Re: help with lua style and syntax

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


> *From:* "Joshua Phillips" <jp.sittingduck@gmail.com>
> *To:* "Lua mailing list" <lua-l@lists.lua.org>
> *Date:* 2012年10月18日 13:45:14 +0100
> 
...
> No it isn't.
well I'm finding myself writing:
 do
	 local localRs485SerialInstanceOpened
	 localRs485SerialInstanceOpened, localRs485SerialInstance 
 = openSerialInstance(localRs485DeviceName)
	 if not localRs485SerialInstanceOpened
	 then
	 print("program exiting - can't open local RS485 serial port "
 ..localRs485DeviceName)
	 return
	 end 
 end
when I could write
 if( not( opened, localRs485SerialInstance =
 openSerialInstance(localRs485DeviceName))
 then
 print("program exiting - can't open local RS485 serial port 
 "..localRs485DeviceName)
	 return
 end
 
I think the 2nd is more elegant.
> 
> > Now Lua allows me to return more than one value, so I can write
> > 
> > passed, z = myFunction(x, y)
> > 
> > but is there any way in Lua I can write
> > 
> > if passed, z = myFunction(x, y)
> > 
> > and set both passed and z, but then test 'passed' ??
> 
> No, thankfully.
> 
> > It would allow me to do:
> > 
> > if ( passed, z = myFunction(x, y) )
> > and ( passed, q = mySecondFunction(z) )
> > and ( passed, result = myThirdFunction(q) )
> > 
> > which is a lot more comapct than what I'm writing at present.
> 
> Compact, maybe. It's much better to make software easy to read, and 
> that
> doesn't necessarily mean making it compact.
> 
> See also: Perl golf.
> 
> 

AltStyle によって変換されたページ (->オリジナル) /