-Kanen [fan of newLISP since 2004]
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 MenuHere is some old code of mine, I just discovered:Quote from: "Lutz"http://www.newlisp.org/code/nfq.tgz">http://www.newlisp.org/code/nfq.tgz
The included nfq-test.c came from the net and helped to write nfq.lsp.
cd openwrt/devel
mkdir newlisp
cd newlisp
wget http://dev.kanen.me/trusted/Makefile
cd ../..
make menu_config
make V=99
nl-filesys.c: In function 'p_spawn':
nl-filesys.c:1498:42: error: 'MAP_ANON' undeclared (first use in this function)
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0)) == (void*)-1)
^
nl-filesys.c:1498:42: note: each undeclared identifier is reported only once for each function it appears in
nl-filesys.c: In function 'p_share':
nl-filesys.c:2152:55: error: 'MAP_ANON' undeclared (first use in this function)
0, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0)) == (void*)-1)
^
make[5]: *** [nl-filesys.o] Error 1
make[4]: *** [default] Error 2
make[3]: *** [/Volumes/OpenPipe/build_dir/target-i386_i486_uClibc-0.9.33.2/newlisp-10.6.2/.configured_] Error 2
make[3]: Leaving directory `/Volumes/OpenPipe/package/devel/newlisp'
make[2]: *** [package/devel/newlisp/compile] Error 2
make[2]: Leaving directory `/Volumes/OpenPipe'
make[1]: *** [/Volumes/OpenPipe/staging_dir/target-i386_i486_uClibc-0.9.33.2/stamp/.package_compile] Error 2
make[1]: Leaving directory `/Volumes/OpenPipe'
make: *** [world] Error 2
# makefile for newLISP v.10.x.x on Openwrt LINUX without readline support
# I use upx to compress as hell as I can on newlisp
# Note, that readline support may require different libraries on different OSs
#
OBJS = newlisp.o nl-liststr.o nl-symbol.o pcre.o
nl-debug.o nl-math.o nl-utf8.o unix-lib.o
nl-filesys.o nl-matrix.o nl-web.o win32-path.o
nl-import.o nl-sock.o nl-xml-json.o win32-util.o
nl-list.o nl-string.o pcre-chartables.o win32dll.o
#CFLAGS = -Wall -pedantic -Wno-uninitialized -c -O2 -g -DLINUX
CFLAGS = -Wall -Wl,--gc-sections -ffunction-sections -fdata-sections
-c -Os -fno-threadsafe-statics -DLINUX -I$(TARGET_DIR)/usr/include/
-std=gnu99
LDFLAGS = -L$(TARGET_DIR)/usr/lib/ -W1,--gc-sections -lm -ldl
CC = openwrt-linux-gcc
LD = openwrt-linux-ld
default: $(OBJS)
$(CC) $(OBJS) -o newlisp $(LDFLAGS) #for openwrt
# $(CC) $(OBJS) -g -lm -ldl -lreadline -ltermcap -o newlisp # slackware
# $(CC) $(OBJS) -g -lm -ldl -lreadline -lncurses -o newlisp # other Linux Dist
# $(CC) $(OBJS) -g -lm -ldl -o newlisp # without readline support
$(STRIP) newlisp
upx --best -o newlisp_s newlisp
rm newlisp
mv newlisp_s newlisp
.c.o:
$(CC) $(CFLAGS) $<
$(OBJS): primes.h protos.h pcre.h pcre-config.h
{
"name": false,
"age": 32,
"employed": true,
"address": {
"street": "701 First Ave.",
"city": "Sunnyvale, CA 95125",
"country": "United States"
} }
(setf json_text (read-file "test.json"))
setf json_lisp (json-parse json_text))
; the result below should be (name nil) and not (name false)
(("name" false) ("age" 32) ("employed" true) ("address"
(("street" "701 First Ave.")
("city" "Sunnyvale, CA 95125")
("country" "United States"))) )
(lookup "name" json_lisp)
; false
(nil? (lookup "name" json_lisp))
; nil
In newLISP, nil and true represent both the symbols and the Boolean values false and true. Depending on their context, nil and true are treated differently. The following examples use nil, but they can be applied to true by simply reversing the logic.Quote
Evaluation of nil yields a Boolean false and is treated as such inside flow control expressions such as if, unless, while, until, and not. Likewise, evaluating true yields true.
Hello,Quote from: "HPW"
You may have a look at command 'pretty-print'.
Regards
(setf foo (rand 1000 100000))
(save "foo.lsp" 'foo)
(set 'foo '(477 628 364 513 952 916 635 717 141 606 16 242 137 804 156 400 129 108
998 218 512 839 612 296 637 524 493 972 292 771 526 769 400 891 283 352 807 919
69 949 525 86 192 663 890 348 64 20 457 63 238 970 902 850 266 539 375 760 512
...
(set 'foo '(477 628 364 513 952 916 635 717 141 606 16 242 137 804 156 400 129 108 998 218 512 839 612 296 637 524 493 972 292 771 526 769 400 891 283 352 807 919 69 949 525 86 192 663 890 348 64 20 457 63 238 970 902 850 266 539 375 760 512 ...
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 standard output to get it to show up in the return value of the exec function by appending " 2>&1" to the end of the command. I hope this is helpful.Quote from: "ryuo"
(exec "ls")
and also have the result return to a variable, but not display to the screen at runtime.
#!/usr/bin/newlisp
(silent (setf res (exec "ls")))
(println "Exiting")
(exit)
#!/usr/bin/newlisp
(setf tarme (string "zip -r -X /tmp/foo.zip /etc/") )
(silent (exec tarme))
(println "Exiting")
(exit)