lua-users home
lua-l archive

RE: Are parenthesis-free calls a Good? (was Re: patch: C-style stringlexing)

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


Alexander Gladysh wrote:
> I personally often use such calls in my micro-DSLs. Like this:
> 
> foo "name"
> {
> bar "bar";
> baz "baz";
> }
> 
> I find this style to be shorter and to better express
> "declarativeness" of the code. Also it is arguable simpler for
> non-programmers to comprehend in some cases. 
> 
> "Non-weird" equivalent would have too many braces to my taste:
> 
> local tmp = foo("name")
> tmp({bar("bar1"); baz("baz")})
> 
> I believe Lua would be a bit less elegant without parenthesis-free
> calls. 
I use similar syntax to describe userdata structures, and automatically
generate C structs, the bindings to Lua and the
serialization/loading/saving. It makes my struct definition looks very
close to what it would look like in C. Without parenthesis-free calls it
would make it much less readable. Here is an example:
struct 'ModelBoneDef' {
 int32 'animid';
 int32 'flags';
 int16_index 'parent';
 int16 'geoid';
 int32 'unknown';
 AnimationBlock(Vec3D) 'translation';
 AnimationBlock(PackedQuaternionAsShorts) 'rotation';
 AnimationBlock(Vec3D) 'scaling';
 Vec3D 'pivot';
} {
 __postload = function(ctype, self, file)
 if self.parent==0 then
 self.parent = nil
 end
 return self
 end;
};
This syntactic sugar is one of the main strength of Lua as a
domain-specific language platform.

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