Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - cavva

#1
newLISP Graphics & Sound /
May 11, 2009, 06:13:33 AM
Quote from: "Lutz"Here is an example how wrap a library for the PPC CPU on older Mac OS X systems, where the normal newLISP FFI does not work because of non cdecl calling conventions:



http://www.newlisp.org/code/wrapper.c">http://www.newlisp.org/code/wrapper.c


thanks a lot
#2
newLISP Graphics & Sound /
May 10, 2009, 07:56:12 AM
ok, i must admit that i don't have understood the 100% of the replies;



i have little knowledge in C and newlisp, two thing that i'm start using because i want to learn more about programming (right now i'm a java programmer)



So, from the start, what a bridge would look like?

In my mind it would simply a "wrapper", so i've written a little c function to test if i was wrong

// testlib.c
//
// compiled on OSX with: gcc testlib.c -bundle -o testlib.so -framework OpenGL

#include stdio.h

#import OpenGL/OpenGL.h
#import OpenGL/gl.h
#import OpenGL/glu.h


int testVertex3d(double x, double y, double z)
{
glVertex3d( x, y, z);
return 1;
}

int testDouble(double x)
{
printf("the number: %fn", x);
return 1;
}
   
/* eof */

(in the include i've removed the "<>", problems with phpbb i think...)

and it doesn't work, probably i'm wrong...

i've also made some test in the area "passing double values" with the tstDouble function, and got strange results... first, the lisp program i'm using:



(set 'TEST_LIB "/Users/carlo/Desktop/test new lisp C/testlib.so")

(import TEST_LIB "testDouble")


(set 'GLUT_LIB "/System/Library/Frameworks/GLUT.Framework/GLUT")

(import GLUT_LIB "glutInit")
(import GLUT_LIB "glutDisplayFunc")
(import GLUT_LIB "glutCreateWindow")
(import GLUT_LIB "glutMainLoop")
(import GLUT_LIB "glutSwapBuffers")


(set 'argc 0)
(set 'argv1 "")
(set 'argv (pack "lu" argv1))

(define (draw)
(testDouble 1.5)
(print "test")
)

(glutInit (address argc) (address argv))
(set 'id (glutCreateWindow "Test OpenGL"))
(glutDisplayFunc (callback 0 'draw))

(testDouble 1.5)
(glutMainLoop)


calling testDouble before glutMainLoop output the correct value, inside 'draw it will output "the number: 16.000000"



have you a little patience for exlain me what's heppening here?
#3
newLISP Graphics & Sound /
May 06, 2009, 06:09:01 AM
thanks lutz,



but how did you know that? is it documented somewhere ?



just curious... in the case i'll encouter a similar problem with others lib
#4
newLISP Graphics & Sound / OpegnGL on OSX PPC
May 05, 2009, 02:53:29 PM
Reading the comment on the opengl demo

(http://www.newlisp.org/syntax.cgi?downloads/OpenGL/opengl-demo-lsp.txt">http://www.newlisp.org/syntax.cgi?downl ... mo-lsp.txt">http://www.newlisp.org/syntax.cgi?downloads/OpenGL/opengl-demo-lsp.txt)



i've read that on ppc i'm not able to see the drawing, and that's true, but could someone explain me why?



It's because float and double are passed correctly only on x86 as i read here?

http://www.newlisp.org/CodePatterns.html#extending">http://www.newlisp.org/CodePatterns.html#extending



Is there a work around?
#5
newLISP Graphics & Sound /
May 04, 2009, 01:56:09 PM
Lutz, with 'callback all works great !!


Quote from: "Lutz"


here is example code using OpenGL and GLUT for registering callbacks:



http://www.newlisp.org/syntax.cgi?downloads/OpenGL/opengl-demo-lsp.txt">http://www.newlisp.org/syntax.cgi?downl ... mo-lsp.txt">http://www.newlisp.org/syntax.cgi?downloads/OpenGL/opengl-demo-lsp.txt



it works well on Mac OS X (Intel processor required) with nothing additional to be installed and works with the GLUT Framework for handling input and window handling.


I know that GLUT is on most platform, but reading some tutorials all says it's only for basic demos, so i've choosen another lib (without knowing if glut fame was real )...



the first was SDL, but on Mac osx the lib need to istantiate a NSAutoreleasePool obj, and i don't have the knowledge required for it



so my second try was GLFW, it's small, simple, portble and written in Carbon... it was love at first sight :)
#6
newLISP Graphics & Sound /
May 03, 2009, 02:16:16 PM
hi newdep,



can you have some example code using glfw?



I'm using newlisp + glfw 2.6 + osx, i've made a little test to see the how "key listener callback" could work, but when i type sometingh the application crash... so i don't understand if i made some mistake ... here is the code:



(load "glfw.lsp" )
(load "gl.lsp" )

(define (reshape width height)
(println "reshape")
)

(define (keypress key action)
(println "keypress")
)

(glfw:Init)

(glfw:OpenWindow 640 400 0 0 0 0 16 0 glfw:GLFW_WINDOW)

(glfw:SetWindowTitle "Test Carlo")
(glfw:SetKeyCallback 'keypress )

(while (!= (glfw:GetKey glfw:GLFW_KEY_ESC) glfw:GL_TRUE)
(begin
(gl:Clear gl:GL_COLOR_BUFFER_BIT)
(glfw:SwapBuffers)
)
)

(glfw:Terminate)

(exit)
#7
Anything else we might add? /
February 11, 2008, 02:04:53 AM
my vote is for the solution number 1, with this "exception":

the first element of a non-quoted list is special, if the list is quoted all element are the same
#8
Anything else we might add? / about Vim syntax file
February 10, 2008, 04:50:38 AM
wondering if is possible to have the function name with a different color;



today the function name and its arguments are all in the same color,

if is possible (asking because i don't know vim syntax well)

would be nice to have "visual" separation between  the two ...
#9
newLISP Graphics & Sound /
December 03, 2007, 12:33:17 AM
WinXP and newLISP 9.2.0 here



it return an error:



array, list or string expected : (env "NEWLISPDIR")


on my default installation (env "NEWLISPDIR") return nil
#10
newLISP newS /
December 01, 2007, 09:30:39 AM
Thanks



I'm reading a book about Lisp, and the examples are all for Common Lisp;

In the code they pass a function as a paramter, then use "apply" to "call" the function ...



but you're right, i don't need apply



Edit:



they use funcall, not apply
#11
newLISP newS / question about apply
December 01, 2007, 08:35:48 AM
How can i "call" a function and get back the result?



Here an examples to explain:



(set 'my-func 'integer?)

(apply my-func 1)
=> nil


How can i "apply" my-func and get back the return value? (true in this case)



I've found that this works

(set 'my-func 'integer?)

(apply my-func (list 1))
=>true


but is this correct thing to do to get what i want?
#12
newLISP newS /
November 20, 2007, 03:05:40 PM
thanks cormullion, you're right.



I need also to change this line in my script

(while (read-line myin) (write-line))

with this

(println (read-line myin))

because with the "while" launching the script ends with the same "new line waiting input"



Is "bc" that doesn't end the "communication" with a line-feed or am i doing something wrong?
#13
newLISP newS / Question about process
November 20, 2007, 01:19:13 PM
I'm trying to run the example found in the documentation about process



(map set '(myin bcout) (pipe))
(map set '(bcin myout) (pipe))  

(process "bc" bcin bcout)

(write-buffer myout "3 + 4n")  ; bc expects a linefeed

(while (read-line myin) (write-line))

(exit)


I've added a write-line and an exit call.

When i launch the script i get a "new line" waiting for some input, the only think i can do is type ^C to terminate the script.



Instead i'm expecting to see the result of "3+4" printed than the script terminated ...



PS: I'm on linux, newlisp v 9.2.4
#14
newLISP newS /
November 12, 2007, 09:54:49 AM
@Lutz


Quote from: "Lutz"
it would give you back an integer but everything coming out of floating point has only about 15 digits of precision, while with int yuu get to about 18 digit. Casting to an int doesn't give you back precision and will cut off all decimals.




thanks Lutz,

didn't know about the difference in the digit precision,

i think i must get some acknowledgement.



What about this?
Quote


Also: all functions in newLISP "know" if they need an integer or float and will automatically convert, so casting normally is only necessary when calling routines imported from C libraries.




is something simple as "call" 'integer? or 'float? on the function arguments or something else?



@cormullion

Thanks, your document was my starting point, but i don't read well the chapter 9 :)
#15
newLISP newS /
November 12, 2007, 06:06:50 AM
umm...



but if i want integer precision then i can "cast" to integer right?



someting like this



(int (add 1 1.5 2))





probably it works only on 32 bit integer ?!