Re: My scripting language - any suggestions?
- From: lican <licaner@xxxxxxxxx>
- Date: Sun, 31 Aug 2008 10:05:00 -0700 (PDT)
Yeah, I thought about it. You're right. ToFloat is not scalable. Maybe
something like: To(Float), To(Type)? It's something between
my .ToType() and the 'to' operator proposed Johannes. Every solution
is better than the ugly (SomeClass)var).SomeMethod() ;) The preference
is to use as few (key)word operators as possible. I'm also thinking
about changing new Class to Class.New() or Class.Create(); It would
create a rather consistent interface with methods like object.Clone()
and maybe object.Destroy(). Also the general idea is that all objects
inherit some general methods from the base object called
'Object' (like Java and C#). The methods can be overridden depending
on the type:
- bool Is( Type )
- bool Instance( Type ) or Of( Type ) or InstanceOf( Type )
- Object To( Type )
- String Serialize();
- bool Unserialize();
- Object Clone();
- void Destroy();
As for the int and float representation... the Value class takes care
of that stuff. It's written in C++ and goes something like this:
[code]
class Value
{
public:
Value();
Value( Value& value );
Value& operator =( Value& value );
void SetNull();
void SetBool( bool b );
void SetInt( int i );
void SetFloat( float f );
void SetString( String* s );
...................................
public:
int type; // NULL, BOOL, INT, FLOAT, STRING, ARRAY, REF, OBJECT,
FUNC, ect
union
{
bool b;
int i;
float f;
} ;
Object* o; // everything else
};
[/code]
It's rather simple, but it works. Most scripting VM work that way.
As for the Serialize and To(String) methods, I find them distinct.
I.e. someone wants to display a float to the user, they do
var.To(Float) and get '1234.0987'. But if someone wants to write the
data to a file Serialize would return 'f:1234.0987' or 'float:
1234.0987'. The thing is I think the type:value can be parsed more
easily than just value.
.
- Follow-Ups:
- Re: My scripting language - any suggestions?
- From: Dmitry A. Kazakov
- Re: My scripting language - any suggestions?
- References:
- Re: My scripting language - any suggestions?
- From: Dmitry A. Kazakov
- Re: My scripting language - any suggestions?
- Prev by Date: Re: My scripting language - any suggestions?
- Next by Date: Re: TXL ANTLR
- Previous by thread: Re: My scripting language - any suggestions?
- Next by thread: Re: My scripting language - any suggestions?
- Index(es):
Relevant Pages
|