oxid я это все знаю, спасибо. Сделал, наследованием от базового типа.
К тому же сделал класс, в котором можно добавлять типы и методы динамически во время выполнения программы. Тип содержит 2 поля список_полей и список_методов, а так же методы добавления, удаления и вызова методов и параметров. Получилось довольно забавно.
SuperStrict
Type _Unknown
Field fields_map:TMap = New Tmap
Field methods_map:TMap = New TMap
Method add_method( name:String , func_callback( o:_Unknown, params:Object[] ) )
methods_map.insert( name , New _Method.Create( func_callback ) )
End Method
Method add_field( name:String, this_type:Object )
fields_map.insert( name , this_type )
End Method
Method get_field:Object( name:String )
If fields_map.contains( name ) Then Return fields_map.ValueForKey( name ) Else Return Null
End Method
Method set_field( name:String , this_type:Object )
If fields_map.contains( name ) Then
fields_map.insert( name , this_type )
End If
End Method
Method rem_field( name:String )
If fields_map.contains( name ) Then
fields_map.remove( name )
End If
End Method
Method rem_method( name:String )
If methods_map.contains( name ) Then
methods_map.remove( name )
End If
End Method
Method call_method( name:String , params:Object[] = Null )
Local this:_Method = New _Method
If methods_map.contains( name )
this = _Method( methods_map.ValueForKey( name ) )
End If
this.callback( Self, params )
End Method
Method print_all_fields()
For Local name:String = EachIn fields_map.keys()
Print name
Next
End Method
Method print_all_methods()
For Local name:String = EachIn methods_map.keys()
Print name
Next
End Method
Method clear_fields()
fields_map.clear()
End Method
Method clear_methods()
methods_map.clear()
End Method
End Type
Local obj:_Unknown = New _Unknown
obj.add_field("x", New _Float.Create( 0.3 ) )
obj.add_field("y", New _Float.Create( 0.7 ) )
obj.add_method("add_x_with_y", add_x_with_y )
obj.call_method("add_x_with_y")
obj.set_field("x" , New _Float.Create( 8.3 ) )
obj.call_method("add_x_with_y")
obj.print_all_fields()
obj.print_all_methods()
obj.call_method("add_x_with_y", [ New _Float.Create( 0.5 ) , New _Float.Create( 0.9 ) ] )
End
Function add_x_with_y( o:_Unknown, params:Object[] = Null )
Local x:Float
Local y:Float
If( params = Null )
x = _Float( o.get_field("x") ).value
y = _Float( o.get_field("y") ).value
Else
x = _Float( params[0] ).value
y = _Float( params[1] ).value
End If
Print ( x + y )
End Function
Type _Method
Field callback( o:_Unknown, params:Object[] )
Method Create:_Method( func_callback( o:_Unknown, params:Object[] ) )
callback = func_callback; Return Self
End Method
End Type
Type _Type End Type
Type _Int Extends _Type
Field value :Int
Method Create:_Int( new_value:Int )
value = new_value; Return Self
End Method
Method get:Int()
Return value
End Method
End Type
Type _Float Extends _Type
Field value :Float
Method Create:_Float( new_value:Float )
value = new_value; Return Self
End Method
Method get:Float()
Return value
End Method
End Type
Type _Double Extends _Type
Field value :Double
Method Create:_Double( new_value:Double )
value = new_value; Return Self
End Method
Method get:Double()
Return value
End Method
End Type
Type _String Extends _Type
Field value :String
Method Create:_String( new_value:String )
value = new_value; Return Self
End Method
Method get:String()
Return value
End Method
End Type
Type _Object Extends _Type
Field value :Object
Method Create:_Object( new_value:Object )
value = new_value; Return Self
End Method
Method get:Object()
Return value
End Method
End Type