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 - xytroxon

#1
I think the problem is that the command-line prompt and initial copyright banner output needs to be suppressed.



Change the line:
#!C:binnewlispnewlisp.exe

To:
#!C:binnewlispnewlisp.exe -c

-- xytroxon
#2
newLISP and the O.S. / Re: Guiserver on Win10
May 23, 2017, 11:05:10 PM
If I remember correctly, you have to install Java on Ubuntu first. Check to see if you have Java istalled.

>java -version

java version "1.7.0_131"
OpenJDK Runtime Environment (IcedTea 2.6.9) (7u131-2.6.9-0ubuntu0.14.04.2)
OpenJDK 64-Bit Server VM (build 24.131-b00, mixed mode)

-- xytroxon
#3
newLISP newS / Re: newLISP in a browser
March 19, 2017, 02:55:15 PM
Found this. Might be as simple as setting a flag!



http://webassembly.org/docs/faq/">//http://webassembly.org/docs/faq/


QuoteWhat's the story for Emscripten users?



Existing Emscripten users will get the option to build their projects to WebAssembly, by flipping a flag. Initially, Emscripten's asm.js output would be converted to WebAssembly, but eventually Emscripten would use WebAssembly throughout the pipeline. This painless transition is enabled by the high-level goal that WebAssembly integrate well with the Web platform (including allowing synchronous calls into and out of JavaScript) which makes WebAssembly compatible with Emscripten's current asm.js compilation model.


-- xytroxon
#4
A potential problem exists in handling UTF-8 string values in UTF-8 enabled versions of newLISP. In UTF-8 versions, the length function would return the number of bytes and not the number of UTF-8 characters in the string. Hence, your function would not return the correct number of characters from your string!



In such cases utf8len must be used. Since single-byte ASCII characters (0-127) are a subset of UTF-8, length function problems may not be noticed until a user has multi-byte (non-English) UTF-8 characters to process.



A further complication is that non-UTF-8 versions of newLISP do not include the utf8len function!



A possible solution is to use this "ambidextrous" strlen function in place of length:



(define (strlen str) (if (= (& (sys-info 9) 128) 128) (utf8len str) (length str)))


But of course it fails to return the correct length if your users are trying to process multi-byte UTF-8 character strings on non-UTF-8 versions of newLISP. Like when dealing with UTF-8 html pages that include "fancy" left and right quotes in "English only" text.



A truly "simplified" or "efficient" version of your function may not be entirely possible depending on how robust you want your code to be - like in module code designed to run on all versions of newLISP.



-- xytroxon
#5
newLISP newS / Re: newLISP v.10.6.4 development
September 27, 2015, 11:41:20 PM
Lutz to the rescue!!!



Adding "cdecl" to import works for all 32bit versions of newLISP I have on my Win7 system.



Below is an emergency working version of curl.lsp, (you may want to wait until kosh fixes his code and tests it more ;>)



While the cURL website has both 32 and 64 bit dlls, the sqlite3 website seems to only be pre-compiled for 32 bit systems, so you may need to stick to 32bit newLISP distros.



http://curl.haxx.se/">//http://curl.haxx.se/

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



;;; curl.lsp

;; @module curl.lsp
;; @description libcurl wrapper
;; @version 0.2
;; @author KOBAYASHI Shigeru (kosh)
;; @license MIT
;; @location https://github.com/kosh04/newlisp-curl

;; ChangeLog:
;; 2015-09-28  add "cdecl" to import calls (xytroxon)
;; 2015-03-10  add testing
;; 2013-12-04  add function curl-get. add dylib (osx).
;; 2011-08-02  first commit.

;; Link:
;;
;; libcurl - API
;; - http://curl.haxx.se/libcurl/c/
;; libcurl - source code examples
;; - http://curl.haxx.se/libcurl/c/example.html

(case ostype
  ("Win32"
   (define libcurl "libcurl.dll"))
  ("Windows" ; v.10.6.3+
   (define libcurl "libcurl.dll"))
  ("Cygwin"
   (define libcurl "cygcurl-4.dll"))
  ("BSD"
   (define libcurl "libcurl.so"))
  ("OSX"
   (define libcurl "libcurl.dylib"))
  ("Linux"
   (define libcurl "libcurl.so.3"))
  (true
   ;; assume unix flavor
   (define libcurl "libcurl.so")))

#include <curl/curl.h>
(import libcurl "curl_strequal" "cdecl")
(import libcurl "curl_strnequal" "cdecl")
(import libcurl "curl_formadd" "cdecl")
(import libcurl "curl_formget" "cdecl")
(import libcurl "curl_formfree" "cdecl")
(import libcurl "curl_getenv" "cdecl")
(import libcurl "curl_version" "cdecl")       ; char *curl_version();
(import libcurl "curl_easy_escape" "cdecl")   ; char *curl_easy_escape(CURL *curl, char *url, int length);
(import libcurl "curl_escape" "cdecl")        ; XXX (deprecated, do not use)
(import libcurl "curl_easy_unescape" "cdecl") ; char *curl_easy_unescape(CURL *curl, char *url, int inlength, int * outlength);
(import libcurl "curl_unescape" "cdecl")
(import libcurl "curl_free" "cdecl")          ; void curl_free(char *ptr);
(import libcurl "curl_global_init" "cdecl")   ; CURLcode curl_global_init(long flags);
(import libcurl "curl_global_init_mem" "cdecl")
(import libcurl "curl_global_cleanup" "cdecl")
(import libcurl "curl_slist_append" "cdecl")
(import libcurl "curl_slist_free_all" "cdecl")
(import libcurl "curl_getdate" "cdecl")
(import libcurl "curl_share_init" "cdecl")
(import libcurl "curl_share_setopt" "cdecl")
(import libcurl "curl_share_cleanup" "cdecl")
(import libcurl "curl_version_info" "cdecl")
(import libcurl "curl_easy_strerror" "cdecl") ; const char *curl_easy_strerror(CURLcode errornum);
(import libcurl "curl_share_strerror" "cdecl")
(import libcurl "curl_easy_pause" "cdecl")

#include <curl/easy.h>
(import libcurl "curl_easy_init" "cdecl")     ; CURL *curl_easy_init();
(import libcurl "curl_easy_setopt" "cdecl")   ; CURLcode curl_easy_setopt(CURL *handle, CURLoption option, parameter);
(import libcurl "curl_easy_perform" "cdecl")  ; CURLcode curl_easy_perform(CURL *handle);
(import libcurl "curl_easy_cleanup" "cdecl")  ; void curl_easy_cleanup(CURL * handle);
(import libcurl "curl_easy_getinfo" "cdecl")  ; CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...);
(import libcurl "curl_easy_duphandle" "cdecl")
(import libcurl "curl_easy_reset" "cdecl")
(import libcurl "curl_easy_recv" "cdecl")
(import libcurl "curl_easy_send" "cdecl")

#include <curl/mprintf.h>
(import libcurl "curl_mprintf" "cdecl")
(import libcurl "curl_mfprintf" "cdecl")
(import libcurl "curl_msprintf" "cdecl")
(import libcurl "curl_msnprintf" "cdecl")
(import libcurl "curl_mvprintf" "cdecl")
(import libcurl "curl_mvfprintf" "cdecl")
(import libcurl "curl_mvsprintf" "cdecl")
(import libcurl "curl_mvsnprintf" "cdecl")
(import libcurl "curl_maprintf" "cdecl")
(import libcurl "curl_mvaprintf" "cdecl")

#include <curl/multi.h>
(import libcurl "curl_multi_init" "cdecl")
(import libcurl "curl_multi_add_handle" "cdecl")
(import libcurl "curl_multi_remove_handle" "cdecl")
(import libcurl "curl_multi_fdset" "cdecl")
(import libcurl "curl_multi_perform" "cdecl")
(import libcurl "curl_multi_cleanup" "cdecl")
(import libcurl "curl_multi_info_read" "cdecl")
(import libcurl "curl_multi_strerror" "cdecl")
(import libcurl "curl_multi_socket" "cdecl")
(import libcurl "curl_multi_socket_action" "cdecl")
(import libcurl "curl_multi_socket_all" "cdecl")
(import libcurl "curl_multi_timeout" "cdecl")
(import libcurl "curl_multi_setopt" "cdecl")
(import libcurl "curl_multi_assign" "cdecl")

#include <curl/curl.h>
(define CURL_MAX_WRITE_SIZE 16384)

;; typedef enum { ... } CURLcode;
(define CURLE_OK 0)
(define CURLE_UNSUPPORTED_PROTOCOL 1)
(define CURLE_WRITE_ERROR 23)

(define CURL_ERROR_SIZE 256)

#define CURLOPTTYPE_LONG          0
#define CURLOPTTYPE_OBJECTPOINT   10000
#define CURLOPTTYPE_FUNCTIONPOINT 20000
#define CURLOPTTYPE_OFF_T         30000

;; typedef enum { ... } CURLoption;
(define CURLOPT_FILE (+ 10000 1))
(define CURLOPT_URL (+ 10000 2))
(define CURLOPT_PORT 3)
(define CURLOPT_INFILE (+ 10000 9))
(define CURLOPT_ERRORBUFFER (+ 10000 10))
(define CURLOPT_WRITEFUNCTION (+ 20000 11))
(define CURLOPT_POSTFIELDS (+ 10000 15))
(define CURLOPT_USERAGENT (+ 10000 18))
(define CURLOPT_HTTPHEADER (+ 10000 23))
(define CURLOPT_WRITEHEADER (+ 10000 29))

(define CURLOPT_VERBOSE 41)
(define CURLOPT_HEADER 42)
(define CURLOPT_NOPROGRESS 43)
(define CURLOPT_NOBODY 43)
(define CURLOPT_POST 47)

(define CURLOPT_FOLLOWLOCATION 52)
(define CURLOPT_SSL_VERIFYPEER 64)
(define CURLOPT_SSL_VERIFYHOST 81)

(define SSL_VERIFYHOST 81)

(define CURLOPT_WRITEDATA CURLOPT_FILE)
(define CURLOPT_READDATA  CURLOPT_INFILE)
(define CURLOPT_HEADERDATA CURLOPT_WRITEHEADER)

(define CURL_GLOBAL_SSL (<< 1 0))
(define CURL_GLOBAL_WIN32 (<< 1 1))
(define CURL_GLOBAL_ALL (| CURL_GLOBAL_SSL CURL_GLOBAL_WIN32))
(define CURL_GLOBAL_NOTHING 0)
(define CURL_GLOBAL_DEFAULT CURL_GLOBAL_ALL)

(define (curl--getstring ptr (len 0))
  (first (unpack (format "s%u" len) ptr)))

;; @syntax (curl-version)
;; @return <string> Returns the libcurl version string.
;; @example
;; (curl-version) => "libcurl/7.30.0 SecureTransport zlib/1.2.5"

(define (curl-version)
  (get-string (curl_version)))

;; @syntax (curl-easy-escape <url>)
;; @param <url>
;; @return <string> Return the encoded url.
;; @example
;; (curl-easy-escape "newlisp.org/?q=index.html#123")
;; => "newlisp.org%2F%3Fq%3Dindex.html%23123"

(define (curl-easy-escape url)
  (letn ((curl (curl_easy_init))
         (res (curl_easy_escape curl url 0))
         (str (get-string res)))
    (curl_free res)
    (curl_easy_cleanup curl)
    str))

;; @syntax (curl-easy-unescape <url>)
;; @param <url>
;; @return <string> Returns the unescaped url.
;; @example
;; (curl-easy-unescape "newlisp.org%2F%3Fq%3Dindex.html%23123")
;; => "newlisp.org/?q=index.html#123"

(define (curl-easy-unescape url)
  (letn ((curl (curl_easy_init))
         (outlen (pack "lu" 0))
         (res (curl_easy_unescape curl url 0 outlen))
         (str (curl--getstring res (get-int outlen))))
    (curl_free res)
    (curl_easy_cleanup curl)
    str))

;; @syntax (curl-simple <url>)
;; @param <url>
;; @example
;; (curl-simple "https://www.google.com/")
;; -> print html data to stdout

(define (curl-simple url (verbose nil))
  (local (curl res)
    (setq curl (curl_easy_init))
    (when (!= curl 0)
      (curl_easy_setopt curl CURLOPT_URL url)
      (curl_easy_setopt curl CURLOPT_VERBOSE (if verbose 1 0))
      ;;(curl_easy_setopt curl CURLOPT_HEADER 0)
      (curl_easy_setopt curl CURLOPT_SSL_VERIFYPEER 0)
      ;;(curl_easy_setopt curl CURLOPT_SSL_VERIFYHOST 0)
      (setf res (curl_easy_perform curl))
      (curl_easy_cleanup curl)
      (if (!= res CURLE_OK)
          (write-line 2 (get-string (curl_easy_strerror res))))
      (= res CURLE_OK))))

;; @syntax (curl-get <url>)
;; @param <url>
;; @return <string> Returns html data.
;; @example
;; (curl-get "https://www.google.com/")
;; => "<HTML><HEAD><meta http-equiv="content-type" ..."
;; (curl-simple url) ~= (print (curl-get url))

(define (curl-get url)
  (local (curl buffer writefn res)
    (curl_global_init CURL_GLOBAL_ALL)
    (setq curl (curl_easy_init))
    (when (!= curl 0)
      (curl_easy_setopt curl CURLOPT_URL url)
      (curl_easy_setopt curl CURLOPT_USERAGENT "Mozilla/5.0")
      (curl_easy_setopt curl CURLOPT_FOLLOWLOCATION 0)
      (curl_easy_setopt curl CURLOPT_NOPROGRESS 1)
      (curl_easy_setopt curl CURLOPT_SSL_VERIFYPEER 0) ; option -k/--insecure
      ;;(curl_easy_setopt curl CURLOPT_SSL_VERIFYHOST 0)
      (setq buffer "")
      (setq writefn (lambda (buf size n data)
                      (extend buffer (curl--getstring buf (* size n)))
                      (* size n)))
      (curl_easy_setopt curl CURLOPT_WRITEFUNCTION (callback 0 'writefn))
      (setq res (curl_easy_perform curl))
      (when (!= res CURLE_OK)
        (setq buffer nil)
        (write-line 2 (get-string (curl_easy_strerror res))))
      (curl_easy_cleanup curl))
    (curl_global_cleanup)
    buffer))

(context MAIN)



-- xytroxon
#6
newLISP newS / Re: newLISP v.10.6.4 development
September 27, 2015, 04:19:35 PM
Okay, I tried Kosh's code and (curl-version) "libcurl") always works,

but crashes on (curl-easy-escape "newlisp.org/?q=index.html#123") or

(curl-get "http://localhost/wiki/">http://localhost/wiki/")



Compiled 10.6.4 on Win 7 without FFI enabled and it has the same hang problem!



As  protozen noted, this code works on 10.6.2 or before and fails on 10.6.3 and 10.6.4 versions.



My sqlite3.dll is from 2010, but works with versions 2.7 and 2.83 sqlite3.lsp on newLISP 10.6.4



-- xytroxon
#7
newLISP newS / Re: newLISP v.10.6.4 development
September 27, 2015, 02:24:44 PM
That sucks!



Another thing to check is that ostype "Win32" was changed to "Windows"



kosh's cURL module has both "Win32"  "Windows" so should work?

https://github.com/kosh04/newlisp-curl">//https://github.com/kosh04/newlisp-curl



-- xytroxon
#8
Hacker News: newLISP

https://news.ycombinator.com/item?id=10279266">//https://news.ycombinator.com/item?id=10279266



newLISP doesn't use linked lists???



(I always secretly suspected Lutz was a C "source"-rer! ;O)



--xytroxon



Update: The "leg lifting" was continued by reddit HackerNews topic thieves.

https://www.reddit.com/r/programming/comments/3mczb5/newlisp/">//https://www.reddit.com/r/programming/comments/3mczb5/newlisp/
#9
Hi Hartrock!



I should of said that the use of unique in my x-load x-import functions would be done at the C code level, inside of the newLISP load and import functions.



This pseudo code was written to show how the $libs list would look after preventing multiple loads from blowing up the $libs list size. This version maintains the order in which modules are loaded, (until a module is loaded more than once). But all unique filepaths are recorded for user inspection.



-- xytroxon
#10
newLISP newS / Re: newLISP v.10.6.4 development
September 25, 2015, 11:46:15 PM
Quote from: "protozen"with 10.6.3 and 10.6.4 on windows newlisp crashes when trying to make ffi calls - I've not tested various libraries but curl.lsp definitely crashes.


Hi protozen!



sqlite3.lsp and sqlite3.dll work fine on my Win7 system (with both versions of newLISP).



Did you install 64 bit newLISP version? 32 bit dlls don't work with 64 bit newLSP and vice versa.



-- xytroxon
#11
Just do a unique list operation after each file path is added.



(set '$libs nil)

(define (add-lib fp)
  (set '$libs (unique (push fp $libs -1)))
  (println fp "-> " $libs)
)

(define (x-load fp)
  (add-lib fp)
)

(define (x-import fp)
  (add-lib fp)
)

(println "Load a newLISP module")
(println "Load File -> $libs")
(x-load   "p1/mod.lsp")
(x-import "p2/bin.dll" "func-1")
(x-import "p2/bin.dll" "func-2")

(println "nLoad my library")
(println  "Load File -> $libs")
(x-load   "p1/lib.lsp")
(x-import "p1/bin.dll" "func-1")
(x-import "p1/bin.dll" "func-2")

(println "nRepeated load example")
(println  "Load File -> $libs")
(x-load   "p3/usr.lsp")
(x-load   "p3/usr.lsp")
(x-load   "p3/usr.lsp")
(x-load   "p3/usr.lsp")
(x-load   "p3/usr.lsp")
(x-load   "p3/usr.lsp")

(println "n$libs-> " $libs)
(exit)


Output:



Load a newLISP module

Load File -> $libs

p1/mod.lsp-> ("p1/mod.lsp")

p2/bin.dll-> ("p1/mod.lsp" "p2/bin.dll")

p2/bin.dll-> ("p1/mod.lsp" "p2/bin.dll")



Load my library

Load File -> $libs

p1/lib.lsp-> ("p1/mod.lsp" "p2/bin.dll" "p1/lib.lsp")

p1/bin.dll-> ("p1/mod.lsp" "p2/bin.dll" "p1/lib.lsp" "p1/bin.dll")

p1/bin.dll-> ("p1/mod.lsp" "p2/bin.dll" "p1/lib.lsp" "p1/bin.dll")



Repeated load example

Load File -> $libs

p3/usr.lsp-> ("p1/mod.lsp" "p2/bin.dll" "p1/lib.lsp" "p1/bin.dll" "p3/usr.lsp")

p3/usr.lsp-> ("p1/mod.lsp" "p2/bin.dll" "p1/lib.lsp" "p1/bin.dll" "p3/usr.lsp")

p3/usr.lsp-> ("p1/mod.lsp" "p2/bin.dll" "p1/lib.lsp" "p1/bin.dll" "p3/usr.lsp")

p3/usr.lsp-> ("p1/mod.lsp" "p2/bin.dll" "p1/lib.lsp" "p1/bin.dll" "p3/usr.lsp")

p3/usr.lsp-> ("p1/mod.lsp" "p2/bin.dll" "p1/lib.lsp" "p1/bin.dll" "p3/usr.lsp")

p3/usr.lsp-> ("p1/mod.lsp" "p2/bin.dll" "p1/lib.lsp" "p1/bin.dll" "p3/usr.lsp")



$libs-> ("p1/mod.lsp" "p2/bin.dll" "p1/lib.lsp" "p1/bin.dll" "p3/usr.lsp")

>Exit code: 0



By inspecting $libs, I can see I have a  bin.dll file conflict originating in mod.lsp



-- xytroxon
#12
Good work!



In keeping with Lutz's succinct newLISP key word naming scheme, (as opposed to Scheme's the-longer-the-run-on-key-word-the-better approach ;o), I would rename $main-args-load-ix to either of the more simply remembered mnemonics:



$libraries  or  $libs



Also does/should your code include import .dll/.so library filepaths?



--xytroxon
#13
newLISP newS / Re: newLISP Development Release v.10.6.3
September 19, 2015, 11:15:18 PM
newLISP manual spelling error.



delete-url

syntax: (delete-file str-url)
#14
Ugh! Of course the "current working directory" is easily found with real-path



(set 'current-dir (real-path))
> C:\Users\Apps\newlisp\work

(change-dir "..")
> true

(set 'current-dir (real-path))
> C:\Users\Apps\newlisp




PS: Both of your code fragments are problematic on Windows ;o)



--xytroxon
#15
On windows, when my newLISP script is executed from a .bat or .cmd file, I can use:



(main-args)
> ("C:\Program Files (x86)\newlisp\newlisp.exe" "C:\Users\Apps\newlisp\work\test.lsp")

(set 'script_name (last (parse (main-args 1) "\")))
> test.lsp

(set 'script_dir (join (0 -1 (parse (main-args 1) "\")) "\"))
> C:\Users\Apps\newlisp\work


Too bad this isn't standard behavior on all platforms. But I think it is operating system dependent.



-- xytroxon