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

Calling sb-functions from javascript

by HPW Sun Aug 26, 2018 11:53 am

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: 525
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: Calling sb-functions from javascript

by Peter Sun Aug 26, 2018 12:02 pm

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: 33
Joined: Thu May 04, 2017 4:25 pm

Re: Calling sb-functions from javascript

by HPW Sun Aug 26, 2018 12:14 pm

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: 525
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: Calling sb-functions from javascript

by Peter Sun Aug 26, 2018 12:33 pm

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: 33
Joined: Thu May 04, 2017 4:25 pm

Re: Calling sb-functions from javascript

by HPW Sun Aug 26, 2018 1:14 pm

Hello Peter,

Thanks for the hint. I will remove them.

Regards
Return to Javascript

Who is online

Users browsing this forum: No registered users and 0 guests