newLISP-interpreter in SketchUp-Ruby

newLISP-interpreter in SketchUp-Ruby

Postby HPW » Sat Apr 04, 2009 8:42 pm

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:
Code: Select all
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:

http://www.alh.net/newlisp/phpbb/index.php
0
Last edited by HPW on Sat Apr 04, 2009 8:45 pm, edited 1 time in total.

HPW 
 

Re: newLISP-interpreter in SketchUp-Ruby

Postby Chris Fullmer » Sat Apr 04, 2009 8:43 pm

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
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: newLISP-interpreter in SketchUp-Ruby

Postby HPW » Sat Apr 04, 2009 8:47 pm

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.
0

HPW 
 

Re: newLISP-interpreter in SketchUp-Ruby

Postby AdamB » Sat Apr 04, 2009 10:20 pm

Am I missing something here? If it has no bindings to the underlying SU objects, whats the point?
0
Developer of LightUp Click for website
User avatar
AdamB 
LightUp Support
LightUp Support
 

Re: newLISP-interpreter in SketchUp-Ruby

Postby HPW » Sat Apr 04, 2009 11:18 pm

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?
0

HPW 
 

Re: newLISP-interpreter in SketchUp-Ruby

Postby AdamB » Sun Apr 05, 2009 7:06 am

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
0
Developer of LightUp Click for website
User avatar
AdamB 
LightUp Support
LightUp Support
 

Re: newLISP-interpreter in SketchUp-Ruby

Postby HPW » Sun Apr 05, 2009 8:18 am

do they have a Mac friendly version?


Lutz (creator of newLISP) wrote on the newLISP-forum:
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?

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.
0

HPW 
 

Re: newLISP-interpreter in SketchUp-Ruby

Postby HPW » Sun Apr 05, 2009 11:16 am

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

Code: Select all
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.
0

HPW 
 

Re: newLISP-interpreter in SketchUp-Ruby

Postby HPW » Tue Apr 14, 2009 8:13 am

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

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.
0

HPW 
 

Re: newLISP-interpreter in SketchUp-Ruby

Postby HPW » Sun Jan 22, 2012 10:10 am

Hello,

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

I make also the newLISP extension to a module.

Interested who want to try it can download here:

http://www.hpwsoft.de/anmeldung/html1/s ... chup2.html

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:
viewtopic.php?f=323&t=42732#p380121

Regards

Hans-Peter
0
Last edited by HPW on Tue Jan 24, 2012 9:22 pm, edited 1 time in total.

HPW 
 

Re: newLISP-interpreter in SketchUp-Ruby

Postby HPW » Mon Jan 23, 2012 8:36 pm

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
0

HPW 
 

Re: newLISP-interpreter in SketchUp-Ruby

Postby Dan Rathbun » Tue Jan 24, 2012 1:23 am

HPW wrote: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.)
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: newLISP-interpreter in SketchUp-Ruby

    Postby Dan Rathbun » Tue Jan 24, 2012 1:32 am

      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.
      0
        I'm not here much anymore. But a PM will fire email notifications.
        User avatar
        Dan Rathbun 
        PluginStore Author
        PluginStore Author
         

        Re: newLISP-interpreter in SketchUp-Ruby

        Postby HPW » Tue Jan 24, 2012 11:01 am

        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
        0

        HPW 
         

        Re: newLISP-interpreter in SketchUp-Ruby

        Postby HPW » Tue Jan 24, 2012 7:44 pm

        Hello,

        I updated the ZIP with the latest corrections.

        Hans-Peter
        0

        HPW 
         

        Re: newLISP-interpreter in SketchUp-Ruby

        Postby HPW » Tue Jan 24, 2012 10:08 pm

        Hello,

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

        Hans-Peter
        0

        HPW 
         

        SketchUcation One-Liner Adverts

        by Ad Machine » 5 minutes ago



        Ad Machine 
        Robot
         



         

        Return to Developers' Forum

        Who is online

        Users browsing this forum: Hansanghak and 11 guests

        Visit our sponsors: