Re: How to use upper case static methods?

Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: How to use upper case static methods?

Herby Vojčík
On 10. 2. 2020 7:53, Zenchess wrote:

> The code I am trying to replicate in amber is:
>
> var sphere = BABYLON.Mesh.CreateSphere("", 10, 1, scene);
> CreateSphere is a static method on the Mesh class according to the
> documentation.
>
> I have tried both:
>
> (BABYLON at: 'Mesh') CreateSphere: 'jacob' value: 10 value: 1.
> and
> BABYLON Mesh CreateSphere: 'jacob' value: 10 value: 1
>
> both fail saying that there is no method "CreateSphere".  Also if I
> inspect the object returned by BABYLON Mesh it just has 'prototype' and
> 'length' and I get errors if I try to inspect the prototype.

It looks like BABYLON.Mesh is a JS function, in which case it is
captured by Amber class BlockClosure (printit 'BABYLON Mesh class' in
workspace, it should say "BlockClosure"). In that case, it is proper
Smalltalk object which only understand messages defined by its methods.
In case a JS functions works also as a namespace (which is the case of a
JS class and its static properties), you can use #provided helper
message, as in:

   BABYLON Mesh provided CreateSphere: 'jacob' value: 10 value: 1

What #provided does it that it wraps the function is JSObjectProxy,
treating it as raw JS object.

In case you never plan to use Mesh as an instance of BlockClosure in
Smalltalk code, you can un-Smalltalkize it forever, by:

   Smalltalk optOut: BABYLON Mesh

somewhere at the app start. After which it is no more treated as a
Smalltalk object but as a raw JS object, is automatically wrapped by
JSObjectProxy behind the scenes and your original

   BABYLON Mesh CreateSphere: 'jacob' value: 10 value: 1

should work.

Herby

P.S.: If there is indeed a problem with inspector failure when you try
to inspect prototype of a BlockClosure, you can fill an issue at
lolg.it/amber/helios. Maybe try if the same happens if you inspect []
(an empty block), so that it is really a generic issue with any
BlockClosure, or it is just something in Mesh.prototype that blows
Helios inspector (I presume you use Helios, not legacy in-page IDE).

> For now I can use inline javascript methods to get around this, but it
> would be nice if there was a way to do it in just amber
>
> --
> You received this message because you are subscribed to the Google
> Groups "amber-lang" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [hidden email]
> <mailto:[hidden email]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/amber-lang/da7dc798-e914-4bd3-a0ea-dad5a72318ff%40googlegroups.com 
> <https://groups.google.com/d/msgid/amber-lang/da7dc798-e914-4bd3-a0ea-dad5a72318ff%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/amber-lang/855509d0-f731-625d-d93f-ae420da17532%40mailbox.sk.