Search found 43 matches

by ryuo
Wed Jan 14, 2015 9:38 pm
Forum: newLISP in the real world
Topic: Ubuntu 14.04 newLISP repl, up,down,right,left key is valid
Replies: 1
Views: 2189

Re: Ubuntu 14.04 newLISP repl, up,down,right,left key is val

Did you compile newlisp with readline? That is what is required to have an advanced command line input to "standard input". Otherwise, you are largely limited to backspace, enter, and regular keys for input. Most special keys won't work without readline or a similar program.
by ryuo
Thu Jan 01, 2015 11:20 pm
Forum: newLISP in the real world
Topic: Access to serial interface with Windows-OS
Replies: 3
Views: 3156

Re: Access to serial interface with Windows-OS

That module is not finished, but it may be usable from C. I forget what state I left it in. I do remember it lacks a newLISP interface.
by ryuo
Wed Dec 10, 2014 11:59 am
Forum: newLISP in the real world
Topic: How to pass a newlisp string to C function as uint8_t* arg
Replies: 1
Views: 2441

Re: How to pass a newlisp string to C function as uint8_t* a

First of all, there's an issue with how you imported the function. You import it as "unsigned int" when "ssize_t" is the same size as "size_t", but signed instead of unsigned. To map this to the proper type, it depends on the platform. Most POSIX implementations on x86 that I know of make ssize_t an...
by ryuo
Sun Dec 07, 2014 9:48 pm
Forum: newLISP in the real world
Topic: How to pass NULL argument to C function
Replies: 3
Views: 3247

Re: How to pass NULL argument to C function

To pass a NULL pointer, you would have to use its integer value, 0. But there is another issue. You are trying to map a variadic C function. These may not be usable from the newLISP FFI API, but it appears libFFI supports them. The newLISP documentation doesn't appear to mention anything about varia...
by ryuo
Wed Nov 26, 2014 2:34 am
Forum: newLISP in the real world
Topic: How to determine type of variable/value?
Replies: 4
Views: 5883

Re: How to determine type of variable/value?

There is no built-in function that I know of that can return the type of any newLISP expression. At best, you may be able to construct your own function that uses the existing predicate functions to return a string that is unique for each cell type.
by ryuo
Tue Nov 25, 2014 9:31 am
Forum: newLISP and the O.S.
Topic: Calling shared lib with "double" not working as expected?
Replies: 3
Views: 6667

Re: Calling shared lib with "double" not working as expected

Think about it. You are importing the function without even declaring what the return type and argument types are. If you have used C a long time, you should recall something called an "implicit function declaration". It is not a good idea to use functions like this, as the C compiler ends up "guess...
by ryuo
Sat Nov 15, 2014 4:13 am
Forum: newLISP in the real world
Topic: (silent) during runtime?
Replies: 3
Views: 4437

Re: (silent) during runtime?

This method should work for all the UNIX-like systems, as this behavior is defined by POSIX IIRC. As for Windows, it also appears to do the same thing. I wrote a simple C program that is compiled with mingw to test this: #include <stdio.h> int main() { fprintf(stdout, "Standard Output\n"); fprintf(s...
by ryuo
Fri Nov 14, 2014 7:48 pm
Forum: newLISP in the real world
Topic: (silent) during runtime?
Replies: 3
Views: 4437

Re: (silent) during runtime?

I assume that newLISP only captures the standard output of the command. Therefore, if the command sends output to the screen, it is probably writing to standard error. I also assume that this command is sent to the system UNIX shell for interpretation. Therefore, you can redirect standard error to s...
by ryuo
Fri Nov 14, 2014 3:58 am
Forum: newLISP in the real world
Topic: Multiple dispatch?
Replies: 4
Views: 3904

Re: Multiple dispatch?

Try this fixed up version: (context 'MAIN:asteroid-asteroid) (define (collide-with a b) (list "BANG" (context) a b)) (context 'MAIN:asteroid-spaceship) (define (collide-with a b) (list "BONG" (context) a b)) (context 'MAIN:spaceship-asteroid) (define (collide-with a b) (list "ZING" (context) a b)) (...
by ryuo
Wed Nov 12, 2014 12:01 am
Forum: Anything else we might add?
Topic: Ability to import C functions from a function pointer?
Replies: 11
Views: 13115

Re: Ability to import C functions from a function pointer?

Forgive me, but not everything here makes much sense to me right now. I'm mostly familiar with imperative languages, so not all of these functional / Lisp concepts are familiar. Some of it I thought I understood, but it seems I still have much to learn about other programming concepts. For all funct...
by ryuo
Tue Nov 11, 2014 3:45 am
Forum: Anything else we might add?
Topic: Ability to import C functions from a function pointer?
Replies: 11
Views: 13115

Re: Ability to import C functions from a function pointer?

Lutz, I have a question about how newLISP reclaims previously allocated memory. Part of what is needed to be done to make a C function callable requires the copying of a string pointer into the aux field of a cell. Do I need to make this string part of a persistent object or such? I'm not sure if my...
by ryuo
Tue Nov 04, 2014 9:16 pm
Forum: Anything else we might add?
Topic: Ability to import C functions from a function pointer?
Replies: 11
Views: 13115

Re: Ability to import C functions from a function pointer?

About the usage of mprotect. I did some digging into it. For it to work, the pointer you give it must be aligned on a page size boundary. This can only be done to my knowledge by allocating with posix_memalign. And to get the page size, you must use the sysconf function. So in all, to make use of mp...
by ryuo
Mon Nov 03, 2014 5:45 pm
Forum: Anything else we might add?
Topic: Ability to import C functions from a function pointer?
Replies: 11
Views: 13115

Re: Ability to import C functions from a function pointer?

Lutz, I examined that cpymem example and discovered how it works. It basically creates a new CDECL type cell with the function pointer as the contents. However, I still must ask you. What does the next and aux fields do? In the example, it appears you copy a string pointer into the aux field, but I ...
by ryuo
Mon Nov 03, 2014 5:41 pm
Forum: So, what can you actually DO with newLISP?
Topic: How to call function each other with declaration
Replies: 3
Views: 5700

Re: How to call function each other with declaration

Something like this?

Code: Select all

(define (foo x)
	(if (> x 0)
		(bar x)
		(- x 1)
	)
)
(define (bar x)
	(if (< x 0)
		(foo x)
		(+ x 1)
	)
)
by ryuo
Sun Nov 02, 2014 10:18 pm
Forum: Anything else we might add?
Topic: Ability to import C functions from a function pointer?
Replies: 11
Views: 13115

Ability to import C functions from a function pointer?

I've been experimenting with libtcc, part of the tcc compiler. One of the features is it can compile C functions during runtime, and you can convert these to a function pointer much like you would when using dlopen to access functions in a shared object. I've been able to execute these functions onc...
by ryuo
Sun Nov 02, 2014 3:36 pm
Forum: Anything else we might add?
Topic: C-style atexit functions?
Replies: 4
Views: 7076

C-style atexit functions?

I've been wondering if you would be willing to add a feature like ISO C's atexit function. Basically, the ability to register functions to be executed when someone calls (exit) from within newLISP or similar. This could be useful for cleaning up global symbols inside a module context or program. I'm...
by ryuo
Sat Oct 11, 2014 11:09 pm
Forum: Anything else we might add?
Topic: FOOP destructors?
Replies: 4
Views: 10021

FOOP destructors?

I've been wondering if it would be a good idea for FOOP objects to be able to define a destructor function. The constructor for FOOP is normally the same name as the context / class of the object. Could the destructor be defined in the same context / class and have the same name as the context / cla...
by ryuo
Fri Sep 05, 2014 2:10 pm
Forum: newLISP in the real world
Topic: newlisp and union
Replies: 2
Views: 2988

Re: newlisp and union

There is no direct support for unions, so you will have to emulate them in a sense. Unions in C all share the same chunk of storage, so the size of the union is therefore equal to the size of the largest member. Therefore, you would be best off mapping it to a single type that encompasses all of the...
by ryuo
Wed Jul 23, 2014 1:01 pm
Forum: newLISP in the real world
Topic: newLISP ctypes module
Replies: 1
Views: 2349

newLISP ctypes module

I have been working on a module to assist with mapping types from the C programming language to newLISP. The idea is to have an API that can help translate sections of the C API by providing aliases for C types and convenient lambda macros for mapping user-defined types. Currently, the only user-def...
by ryuo
Mon Jul 14, 2014 5:23 am
Forum: Anything else we might add?
Topic: get-wide-string builtin function?
Replies: 6
Views: 6900

Re: get-wide-string builtin function?

I've been thinking that an additional optional parameter specifying the "character size" to use when looking for a null terminator would be a nice addition to the get-string function. This would be the number of bytes used for a single element in the string. Obviously, the number of bytes cannot be ...
by ryuo
Mon Jul 07, 2014 9:35 am
Forum: Anything else we might add?
Topic: get-wide-string builtin function?
Replies: 6
Views: 6900

get-wide-string builtin function?

I was able to work out a user-defined function for converting a wchar_t array to a layout that appears compatible with what the 'unicode' function does. However, I was wondering if it could be converted to a builtin primitive function. It seems like a good idea to me because there is already a built...
by ryuo
Sat Jul 05, 2014 8:38 am
Forum: newLISP in the real world
Topic: how to remove all attribute-list in diference level of SXML?
Replies: 8
Views: 5625

Re: how to remove all attribute-list in diference level of S

I don't know if this is what you wanted, but I was able to dig up a way to get access to all the occurences of 'bananas' in the list. (set 'data '((apples 123) (bananas 123 45) (bananas 123 678) (pears 7))) (setf (data (((ref-all 'bananas data) 1) 0)) '(bananas 0 0)) (println data) (exit) ref-all fi...
by ryuo
Fri Jul 04, 2014 4:48 am
Forum: Anything else we might add?
Topic: Missing unsigned types for FFI interface?
Replies: 1
Views: 4320

Missing unsigned types for FFI interface?

Is there a particular reason why unsigned long and unsigned long long are missing from the FFI code? I see that unsigned types exist for everything else, but not for these. Specifically, I am referring to their absence from the ffi_types array. I would have expected these to exist. Their absence mak...
by ryuo
Thu Jul 03, 2014 7:00 am
Forum: Anything else we might add?
Topic: Serial Port Module?
Replies: 6
Views: 8613

Re: Serial Port Module?

Lutz, you also mention the possibility of loading the C functions I use internally at runtime, but I do not consider this wise. I use a lot of constants which are actually preprocessor macros that have no guarantees about what their value will be on other implementations. And I can't load these at r...
by ryuo
Mon Jun 30, 2014 2:59 pm
Forum: Anything else we might add?
Topic: Serial Port Module?
Replies: 6
Views: 8613

Re: Serial Port Module?

Ideally I think it would be statically linked into the interpreter, as it is a very small library, only requiring standard system libraries. The standard C library is all it requires on UNIX systems, and for windows it can use one of the standard system libraries for that system. Windows has its own...