Google Groups Home
Help | Sign in
native values in objects from c
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Michael Wohlwend  
View profile
 More options Aug 29 2006, 7:59 am
Newsgroups: fa.caml
From: "Michael Wohlwend" <mich...@fantasymail.de>
Date: Tue, 29 Aug 2006 11:59:56 UTC
Local: Tues, Aug 29 2006 7:59 am
Subject: [Caml-list] native values in objects from c
with that code:

class x = object
 val name = "hoho"
end;;

let ho = new x in ...

how do I access the field name form C?

The docu says it should be the third field of the block, but that doesn't work for me (it has Tag 0, not 252 for strings ...)

cheers,
 Michael

--

Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jacques Garrigue  
View profile
 More options Aug 29 2006, 9:38 am
Newsgroups: fa.caml
From: Jacques Garrigue <garri...@math.nagoya-u.ac.jp>
Date: Tue, 29 Aug 2006 13:38:53 UTC
Local: Tues, Aug 29 2006 9:38 am
Subject: Re: [Caml-list] native values in objects from c
From: "Michael Wohlwend" <mich...@fantasymail.de>

> with that code:

> class x = object
>  val name = "hoho"
> end;;

> let ho = new x in ...

> how do I access the field name form C?

> The docu says it should be the third field of the block, but that doesn't work for me (it has Tag 0, not 252 for strings ...)

Well, since fields start at 0, the 3rd field is number 2.

# Obj.size (Obj.repr ho);;
- : int = 3
# Obj.tag (Obj.field (Obj.repr ho) 2);;                    
- : int = 252

Jacques Garrigue

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Wohlwend  
View profile
 More options Aug 29 2006, 10:09 am
Newsgroups: fa.caml
From: "Michael Wohlwend" <mich...@fantasymail.de>
Date: Tue, 29 Aug 2006 14:09:47 UTC
Local: Tues, Aug 29 2006 10:09 am
Subject: Re: [Caml-list] native values in objects from c

-------- Original-Nachricht --------

> Well, since fields start at 0, the 3rd field is number 2.

thanks for helping; actually my fault was to think the elements are linear ordered, even if the class is inherited (I want to get the first value of the base). The values are ordered reverse of definition, whereas the docu says:
"Instance variables are stored in the order in which they appear in the class definition"

In the end I want to hide public methods which give you access the the pointer to the c++ object and hiding an external method is easy.

cheers
 Michael

--

Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jacques Garrigue  
View profile
 More options Aug 31 2006, 3:11 am
Newsgroups: fa.caml
From: Jacques Garrigue <garri...@math.nagoya-u.ac.jp>
Date: Thu, 31 Aug 2006 07:11:52 UTC
Local: Thurs, Aug 31 2006 3:11 am
Subject: Re: [Caml-list] native values in objects from c
From: "Michael Wohlwend" <mich...@fantasymail.de>

> > Well, since fields start at 0, the 3rd field is number 2.

> thanks for helping; actually my fault was to think the elements are linear ordered, even if the class is inherited (I want to get the first value of the base). The values are ordered reverse of definition, whereas the docu says:
> "Instance variables are stored in the order in which they appear in the class definition"

> In the end I want to hide public methods which give you access the the pointer to the c++ object and hiding an external method is easy.

Aargh, you're right. The behaviour changed between 3.08 and 3.09.
In 3.08, fields are still ordered in definition order, including
inherited ones, but in 3.09, due to an optimization, inherited fields
appear after newly defined ones. The trouble is that this being due
to an optimization, this may change again, so it is not a good idea to
depend on it.
Note also that it is pretty easy to define another object, with the
same type as the one you want to interface with C++, but with
completely different fields. I.e., accessing object fields from the C
side is always dangerous.
A better approach it to add a method which returns the field with an
abstract type, this way users cannot break the type system.

Jacques Garrigue

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Wohlwend  
View profile
 More options Aug 31 2006, 4:33 am
Newsgroups: fa.caml
From: "Michael Wohlwend" <mich...@fantasymail.de>
Date: Thu, 31 Aug 2006 08:33:22 UTC
Local: Thurs, Aug 31 2006 4:33 am
Subject: Re: [Caml-list] native values in objects from c

-------- Original-Nachricht --------
Datum: Thu, 31 Aug 2006 15:55:12 +0900 (JST)
Von: Jacques Garrigue <garri...@math.nagoya-u.ac.jp>
An: mich...@fantasymail.de
Betreff: Re: [Caml-list] native values in objects from c

> Aargh, you're right. The behaviour changed between 3.08 and 3.09.
> In 3.08, fields are still ordered in definition order, including
> inherited ones, but in 3.09, due to an optimization, inherited fields
> appear after newly defined ones. The trouble is that this being due
> to an optimization, this may change again, so it is not a good idea to
> depend on it.

o.k., accessing the field from c allready seemed hacky to me :-)

> A better approach it to add a method which returns the field with an
> abstract type, this way users cannot break the type system.

o.k., seems indeed the safer way.

thanks,
 Michael

--

Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google