• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

NewLISP-interpreter in SketchUp-Ruby

Scheduled Pinned Locked Moved Developers' Forum
16 Posts 4 Posters 3.2k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    HPW
    last edited by HPW 4 Apr 2009, 19:42

    As a longtime supporter of the newLISP-project (http://www.newlisp.org/) I was interested in running the interpreter in SketchUp.
    Looking at the various sample of the ruby-Win32API here in the forum and my previous experiences with embedding newLISP in other enviroments let me try it out.

    So I copied Win32API.so and the newlisp.dll into the plugin folder.

    Here is the console view:

    
    require 'Win32API'
    true
    newLISP = Win32API.new("C;\\Program Files\\Google\\Google SketchUp 7\\Plugins\\newlisp.dll", "newlispEvalStr", ['P'], 'P')
    #<Win32API;0x836c938>
    newLISP.Call("(sys-info)")
    (363 268435456 360 1 0 2048 6064 10003 70)
    newLISP.Call("(setq a(+ 10 10))")
    20
    newLISP.Call("(setq b(+ a 10))")
    30
    
    

    You see that you can pass a lisp-string from ruby to newlisp and get back a result-string.
    Variables preserve their state between calls.
    Reading Lisp-Data gets a lot easier with access to an lisp-interpreter!! 😉)

    Note: newLISP is GPL so you may install it seperatly and load it from:
    "C:\Program Files\newlisp\newlisp.dll"

    For question on newLISP take a look to the exelent doc or visit the forum:

    404 Not Found

    favicon

    (www.alh.net)

    1 Reply Last reply Reply Quote 0
    • C Offline
      Chris Fullmer
      last edited by 4 Apr 2009, 19:43

      Sounds neat! PC onl then I'm guessing? do they have a Mac friendly version? (not that I need it, but there are lots of Mac people around).

      Chris

      Lately you've been tan, suspicious for the winter.
      All my Plugins I've written

      1 Reply Last reply Reply Quote 0
      • H Offline
        HPW
        last edited by 4 Apr 2009, 19:47

        newLISP runs on the MAC and on a lot other plattforms.
        I am not sure about the DLL/SO-calling from ruby to modules on the MAC.
        I posted a related question to the OSX section in the newLISP forum.

        1 Reply Last reply Reply Quote 0
        • A Offline
          AdamB
          last edited by 4 Apr 2009, 21:20

          Am I missing something here? If it has no bindings to the underlying SU objects, whats the point?

          Developer of LightUp Click for website

          1 Reply Last reply Reply Quote 0
          • H Offline
            HPW
            last edited by 4 Apr 2009, 22:18

            @unknownuser said:

            If it has no bindings to the underlying SU objects, whats the point?

            First it can be usefull for someone who wants to import lisp-base data into SU.

            And when there would be any DLL which would export such command for accessing the SU objects newlISP could '(import ....)' this command.

            Are there other extensions with bindings to SU?

            1 Reply Last reply Reply Quote 0
            • A Offline
              AdamB
              last edited by 5 Apr 2009, 06:06

              I should explain. The Ruby in SU isn't just a Ruby interpreter included in the package - in the same way as newLISP is an interpreter. The Ruby you get in SU is integrated into SU, so SU data structures appear as first class objects in Ruby. Without this, there is just not a lot you can do with newLISP. Sure, you can create some strings that you can pass to Ruby but you get no advantage to running newLISP in the SU environment compared to running outside and writing to a file.

              But ultimately, you're right, if you find it useful for your work, knock yourself out.

              Adam

              Developer of LightUp Click for website

              1 Reply Last reply Reply Quote 0
              • H Offline
                HPW
                last edited by 5 Apr 2009, 07:18

                @unknownuser said:

                do they have a Mac friendly version?

                Lutz (creator of newLISP) wrote on the newLISP-forum:

                @unknownuser said:

                Should be possible, the newLISP library behaves like a normal C library on Mac OS X with cdecl calling conventions.

                So can Ruby on the MAC import C librarys?

                @unknownuser said:

                But ultimately, you're right, if you find it useful for your work, knock yourself out.

                That was my point here, I see it as an addition to ruby and not an replacement.
                Of cource some kind of callback-possibilitys would be even better.
                I have done this in enviroments like delphi and neobook.
                So still room for improvments.

                1 Reply Last reply Reply Quote 0
                • H Offline
                  HPW
                  last edited by 5 Apr 2009, 10:16

                  Making slow progress with ruby calling after inspecting the exported functions from msvcrt-ruby18.dll:

                  
                  require 'Win32API'
                  true
                  newLISP = Win32API.new("C;\\Program Files\\Google\\Google SketchUp 7\\Plugins\\newlisp.dll", "newlispEvalStr", ['P'], 'P')
                  #<Win32API;0x813bb48>
                  newLISP.Call("(import {C;\\Program Files\\Google\\Google SketchUp 7\\msvcrt-ruby18.dll} {rb_eval_string})")
                  rb_eval_string <1CF2F30>
                  newLISPret = newLISP.Call("(rb_eval_string {puts \"Ruby called from Lisp\"})")
                  Ruby called from Lisp
                  4
                  newLISP.Call("(rb_eval_string {VERSION})")
                  47157480
                  
                  

                  Not sure what the return-value 4 or 47157480 from rb_eval_string means.
                  What is the return-type of ruby's VERSION?
                  Still searching to get values from ruby-calls back to newLISP.

                  1 Reply Last reply Reply Quote 0
                  • topic:timeago-later,9 days
                  • H Offline
                    HPW
                    last edited by 14 Apr 2009, 07:13

                    After making a helper-DLL RubyCall.dll I get further progress:

                    @unknownuser said:

                    require 'Win32API'
                    true
                    newLISP = Win32API.new("C:\Program Files\Google\Google SketchUp 7\Plugins\newlisp.dll", "newlispEvalStr", ['P'], 'P')
                    #Win32API:0x8d26ef8
                    newLISP.Call("(import {C:\Program Files\Google\Google SketchUp 7\RubyCall.dll} {CreateRuby})")
                    CreateRuby <499C1B4>

                    newLISP.Call("(import {C:\Program Files\Google\Google SketchUp 7\RubyCall.dll} {EvalRuby})")
                    EvalRuby <499C23C>

                    newLISP.Call("(get-string(CreateRuby ""))")
                    "Ruby interpreter loaded!"

                    newLISP.Call("(get-string(EvalRuby {name = Sketchup.app_name}))")
                    "Google SketchUp"

                    newLISP.Call("(import {C:\Program Files\Google\Google SketchUp 7\RubyCall.dll} {GetRubyOutput})")
                    GetRubyOutput <499C338>

                    newLISP.Call("(get-string(EvalRuby {puts "Hello World!";test = 2+2}))")
                    "4"

                    newLISP.Call("(get-string(GetRubyOutput ""))")
                    "Hello World!\r\n"

                    So now I get back all kind (types) of return-values and the accumulated consol-output form ruby's puts commands.

                    1 Reply Last reply Reply Quote 0
                    • topic:timeago-later,3 years
                    • H Offline
                      HPW
                      last edited by 23 Jan 2012, 19:36

                      Hello,

                      After even more help from Dan with the pdScript-extension I ported the same module and language support to the newLISP extension and make a version 1.01
                      Still under the link above to download.

                      Hans-Peter

                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by 24 Jan 2012, 00:23

                        @hpw said:

                        After even more help from Dan with the pdScript-extension I ported the same module and language support to the newLISP extension ...

                        I suppose we should make a Mixin Library module from that, so it can be mixed into any module, without "porting" (which is tweaking module wrapper name and file info in the doc header, [which still refers to PdScript in the NewLisp langLoad.rb file, BTW.])

                        That way there is only one copy of the code (in memory.)

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • Dan RathbunD Offline
                          Dan Rathbun
                          last edited by 24 Jan 2012, 00:32

                          NewLip_ext.rb

                          line 19, is like this (symbolic args.):
                          @@extension = SketchupExtension.new ( *arg1*, *arg2* )

                          Ruby 1.8.6 does not like a space between the method name and the ( of the argument list. The interpreter will often spit out a warning, and sometimes refuse to load the file (causing a LoadError exception to be raised.)

                          Should be:
                          @@extension = SketchupExtension.new( *arg1*, *arg2* )

                          You should also get in the habit of wrapping all argument lists in ( ), as they will be required in later versions of Ruby.

                          I'm not here much anymore.

                          1 Reply Last reply Reply Quote 0
                          • H Offline
                            HPW
                            last edited by 24 Jan 2012, 10:01

                            Hello Dan,

                            Oops, typo on my side. Will correct it later.
                            Strange: It does work for me without errors.

                            I hopy that ruby does not get more formating aware like for example python.

                            Hans-Peter

                            1 Reply Last reply Reply Quote 0
                            • H Offline
                              HPW
                              last edited by 24 Jan 2012, 18:44

                              Hello,

                              I updated the ZIP with the latest corrections.

                              Hans-Peter

                              1 Reply Last reply Reply Quote 0
                              • H Offline
                                HPW
                                last edited by 24 Jan 2012, 20:22

                                Hello,

                                After some deeper insights with ruby module with the pdScript-extension here:
                                http://forums.sketchucation.com/viewtopic.php?f=180&t=42730

                                I make also the newLISP extension to a module.

                                Interested who want to try it can download here:

                                HPW's newLISP page

                                favicon

                                (www.hpwsoft.de)

                                The ZIP contains 1 file at the toplevel:
                                newLISP_ext.rb

                                The rb is the extension which must be activated in the preferences.
                                The subfolder contains the DLL's and samples. Preserve the folder when you unpack the ZIP.
                                The extension adds a menu to the plugins menu with some demo.

                                The Win32API extension is needed from here:
                                http://forums.sketchucation.com/viewtopic.php?f=323&t=42732#p380121

                                Regards

                                Hans-Peter

                                1 Reply Last reply Reply Quote 0
                                • H Offline
                                  HPW
                                  last edited by 24 Jan 2012, 21:08

                                  Hello,

                                  I made a small page for the sketchup plugins on my website.
                                  I updated the above link for the download.

                                  Hans-Peter

                                  1 Reply Last reply Reply Quote 0
                                  • 1 / 1
                                  1 / 1
                                  • First post
                                    15/16
                                    Last post
                                  Buy SketchPlus
                                  Buy SUbD
                                  Buy WrapR
                                  Buy eBook
                                  Buy Modelur
                                  Buy Vertex Tools
                                  Buy SketchCuisine
                                  Buy FormFonts

                                  Advertisement