newlisp and the C++ revolution

Started by newdep, July 08, 2009, 01:40:57 PM

Previous topic - Next topic

newdep

It seems that more and more library's are moving towards c++

This hasnt been always the case. I know some pretty nice languages

that where c library based and also Gui's and other applications..



Somehow it all slightly is moving towards c++ and being a newlisp user

im wondering how to overcome the fact that newlisp cant keep up with

binding to library's.



Im far from a c++ programmer so i dont know the details but there

must be a way to interact with c++ library's somehow.. and it is

discussed befor here but not deep enough!



This topic is realy eating me as I have some nice projects on the stack

that get dusty because im not willing to learn c++ but want a binding

to a highlevel language..



Is there a way to adjust or add-on something/somehow to newlisp to

make c++ library binding happen...

Not only for mysake but for the sake of newlisp's future perhpas..



Just a mind storm that keeps me awake...
-- (define? (Cornflakes))

newdep

#1
How does Python do this?

I know that python can do c++ library's by the use of a language (c++?)

that transforms it back to python functions.. How its done i dont know

but this kind of interface is actualy a solution..
-- (define? (Cornflakes))

newdep

#2
reading reading..reading..

The only way to do this is writing a wrap around the cpp lib.

And there is no way of doing this without the intervention of cpp.

This asks for creativity...and is btw a generic 'problem' of cpp.

case closed.. again..pitty..
-- (define? (Cornflakes))

Lutz

#3
For Python there are tools available to generate wrappers automatically, e.g. from: http://www.language-binding.net">http://www.language-binding.net . Probably these could be adapted for newLISP too; but then it is probably quicker to write a wrapper yourself in 'C'. If one is doing a module anyway, this is not much of additional work.

xytroxon

#4
For a more generic method:



SWIG - (Simplified Wrapper and Interface Generator)

http://www.swig.org/">//http://www.swig.org/
QuoteSWIG is an interface compiler that connects programs written in C and C++ with scripting languages such as Perl, Python, Ruby, and Tcl. It works by taking the declarations found in C/C++ header files and using them to generate the wrapper code that scripting languages need to access the underlying C/C++ code. In addition, SWIG provides a variety of customization features that let you tailor the wrapping process to suit your application.


-- xytroxon
\"Many computers can print only capital letters, so we shall not use lowercase letters.\"

-- Let\'s Talk Lisp (c) 1976

itistoday

#5
Yes it would be cool if newLISP had this capability.  I for one would like to use it with a project like http://www.ogre3d.org/">Ogre3D, which is written in C++.  Maybe someone will look into doing the SWIG for newLISP... damn, I wish I could clone myself (anyone seen Multiplicity?)..
Get your Objective newLISP groove on.

Elica

#6
Just curious about C++ libraries which do use OOP within their APIs. How would one deal with stuff like this?

itistoday

#7
Quote from: "Elica"Just curious about C++ libraries which do use OOP within their APIs. How would one deal with stuff like this?


I would guess that you would somehow let C++ deal with that since newLISP can't do OOP like C++.



Something like this (warning, written on the whim):


(set 'cppObj (MyCppClass::getInstance))
(MyCppClass::setName cppObj "Dog")


What's interesting is that MyCppClass becomes a context in newLISP, with a function called ":getInstance" and ":setName", where the former is a static function and the latter is a ... whatchamacallit, instance function?



Whether these functions would be mapped directly to their corresponding C++ methods, or through some sort of a trampoline function, I don't know.
Get your Objective newLISP groove on.

itistoday

#8
Then there's also the question of C++ namespaces and what to do about them.  Because C++ can have namespaces within namespaces (I think), it may actually be a real pain to get newLISP to work with it really nicely like above.



You would probably have to have some sort of convention like they PyObjC wrapper, where special characters like the underscore are used. Thereby you would simply have symbols pointing directly to their corresponding C++ counterparts.



It would also be interesting to consider how to use newLISP contexts in this situation to get the best performance and usability out of such a system, as the number of symbols that could be imported from a large C++ project would be staggering...
Get your Objective newLISP groove on.

newdep

#9
Actualy Im hitting this question because the Smartphone technology is

all based on C++. Porting newlisp to an ARM version isnt propably the

most difficult part but letting it interact with C++ is.



Btw.. Does someone have a SmartPhone here? With Symbian on it?

Python is already there... Perl is half way.. so time for newlisp to Run

on more then only Intel..i guess .. (I already kicked off with the ARMEL version ;-)





http://www.symbian.org/">//http://www.symbian.org/



PS: Btw... Intel is catching up in the Smartphone/handheld area..

Not quick but they are trying.. So Symbian does already run on the

Intel/Atom.
-- (define? (Cornflakes))

xytroxon

#10
You could always compile newLISP as C++... Change .c files to .cpp etc... But, then you get to debug it ;)



SWIG helps you with the C++ Class stuff... but to program it from newLISP, you still need to understand C++... A library like Ogre3D really needs to be run from C++ code to be fast... Even so, Python does have an interface you might look at:

http://en.wikipedia.org/wiki/Python-Ogre">//http://en.wikipedia.org/wiki/Python-Ogre



But the major problem, is that C++ compiler "name mangling" of dll function names is not consistant... Visual C++ is different than MinGW is different than WatCom, Borland etc...



So to effectively use SWIG, the library and newLISP++ must be compiled with the same compiler brand...



And as Lutz has proven, Java is already useable from newLISP... And Java programming is "safer" than C++ programming... (LOL)



Also interfacing C librarys from C++ is very easy... But C++ libraries from C is very messy...



So retargeting newLISP to C++ may seem like a good idea, but C++ compiled code quickly expands in executable code size and that also reduces execution speed... All that object oriented functionality comes at a cost... And negating the newLISP size and speed advantage over other scripting languages...



So nothing is really as easy as it first seems... :)



-- xytroxon
\"Many computers can print only capital letters, so we shall not use lowercase letters.\"

-- Let\'s Talk Lisp (c) 1976

pjot

#11
Well the answer maybe here:



http://www.isotton.com/devel/docs/C++-dlopen-mini-HOWTO/C++-dlopen-mini-HOWTO.html">http://www.isotton.com/devel/docs/C++-d ... HOWTO.html">http://www.isotton.com/devel/docs/C++-dlopen-mini-HOWTO/C++-dlopen-mini-HOWTO.html



It is a lot of work though, adding 'EXTERN C' to your relevant functions ;-)



Well crap, C++ is kind of a hype anyway. For small applications you're looking at, it's really useless. Do you know how many lines of code one needs for a simple 'Hello world' application in C++?



But if you're bound with your Nokia environment, it's a pain of course. I guess the only thing you can do is writing your own wrapper ;-)



Cheers

Peter

Elica

#12
Quote from: "pjot"Do you know how many lines of code one needs for a simple 'Hello world' application in C++?


The same number of lines as in C.


#include <iostream>
 
int main()
{
    std::cout << "Hello, world!n";
}


More examples including some funny languages are available in http://en.wikibooks.org/wiki/List_of_hello_world_programs">Transwiki:List of hello world programs

pjot

#13
OK. Now let's do the same in newLisp:

(println "Hello, world!")

Looks less code to me... ;-)