Calling sb-functions from javascript

Using Javascript from SpiderBasic
HPW
Posts: 35
Joined: Thu May 04, 2017 4:25 pm

Calling sb-functions from javascript

Post by HPW »

Hello,

A question:
I injected some JavaScript calls ito the Body of the spiderapp.
I want to Access the spider-objects from there like:

Code: Select all

    <script type='text/javascript'>
<!--
      var Module = {
        preRun: [],
        postRun: [(function() {
          newlispEvalStr = Module.cwrap('newlispEvalStr', 'string', ['string']); 
        })],
        print: (function() { return function(text) { }; })(),
        printErr: function(text) { },
        setStatus: function(text) {
            f_spider_disablegadget(3,0);
            f_spider_setgadgettext(5,text);
        }
      };
-->
    </script>
But Console repors that the functions are undefined.
So how do I access objects or commands from main-html/JavaScript?

Regards
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Calling sb-functions from javascript

Post by Peter »

Hello Hans-Peter,

replace f_spider_disablegadget(...) with spider_DisableGadget(...) and f_spider_setgadgettext(...) with spider_SetGadgetText(...).

(and note that the code block is commented out (<!-- .... -->) and therefore cannot be called.)

Greetings ... Peter
HPW
Posts: 35
Joined: Thu May 04, 2017 4:25 pm

Re: Calling sb-functions from javascript

Post by HPW »

Hello Peter,

Thanks again for the hint.
I had tested the code before but dammned case sensitivity was the problem.
Works now. Now the Picture gets clearer how things work together in sb.

[quote](and note that the code block is commented out (<!-- .... -->) and therefore cannot be called.)[\quote]

I had copied it from other sample and it works as expected. When I remember right the comment tag is not interreted in script-blocks as in html.

I also managed to build a newlisp-module.

Code: Select all

newlispresultstr.s = newlispCall(newlispsource.s)
Regards
Hans-Peter
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Calling sb-functions from javascript

Post by Peter »

HPW wrote:When I remember right the comment tag is not interreted in script-blocks as in html.
yes, you're right. However, you will then get an "unexpected token" error in the JS block.

Greetings ... Peter
HPW
Posts: 35
Joined: Thu May 04, 2017 4:25 pm

Re: Calling sb-functions from javascript

Post by HPW »

Hello Peter,

Thanks for the hint. I will remove them.

Regards
Post Reply