[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C++ syntax for Lua
- From: Dong Feng <middle.fengdong@...>
- Date: Fri, 14 Dec 2012 15:13:35 +0800
With template, to make C++ "similar" to any language is not
impossible. There is even a parser implemented purely by template.
http://www.boost.org/doc/libs/1_52_0/libs/spirit/doc/html/index.html
Only the "similarity" is usually not pretty and the error handling is
not good. (I tested Spirit in around 2004 and it has silent failure
when dealing with left-recursive).
2012/12/14 Rapin Patrick <rapin.patrick@gmail.com>:
> Despite usual believe, it happens that Lua and C++ can have a very similar
> syntax.
> I just discovered it. Consider the following code:
>
>
> f=print debug.setmetatable(nil, {__len=f,__lt=f,__call=f,__index=f})_=
>
> #include <iostream>
> #include <stdlib.h>
>
> namespace
> {
> enum { TRUE, FALSE, MAYBE };
>
> template<T>
> class {
> public:
> int (aMethod)(int, void);
> void (convertToFloat)(double[8], float[8]);
> protected:
> double (getValue)();
> };
>
> int (globalFunction) (void);
> }
>
> Is it a valid Lua program? YES, although it outputs essentially debug
> information.
> Is it a valid C++ program ? No, but nearly !
>
>
> --
> -- Patrick Rapin
> -- coauthor of "Le guide de Lua et ses applications", D-BookeR