1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-09 18:06:35 +03:00
mal/php
Nicolas Boulenguez e6d41de4d5 load-file: accept empty file or final comment, return nil
Let `load-file` append a new line in case last line contains a
comment.

Also append `nil` so that the return value is predictible. Remove the
existing explicit `nil` from existing sources.

Adapt documentation and tests.
2019-07-28 13:08:05 +02:00
..
tests Runtest should fail on bad test data. Fix interop tests. 2019-01-28 10:27:41 -06:00
core.php php: Convert hash-map keys into strings before returning them. 2019-07-07 18:19:39 +01:00
Dockerfile Travis: add java, php, ps. 2015-10-05 23:31:05 -05:00
env.php All: add keywords. 2015-01-09 16:16:50 -06:00
interop.php PHP: Wrap some native "language constructs". 2018-07-12 20:25:32 +08:00
Makefile Convert to loccount based stats calculation. 2019-03-20 23:34:21 -05:00
printer.php php: Convert hash-map keys into strings before returning them. 2019-07-07 18:19:39 +01:00
reader.php gnu-smalltalk, go, js, lua, php, rust, ts: Detect more unterminated strings. 2019-05-16 22:06:02 +01:00
readline.php Allow web exec of a .mal file via symlinked php script. 2016-10-25 10:35:14 +08:00
README.md Updated PHP native interop interface. 2018-06-25 09:59:15 +08:00
run Refactor to use run scripts, remove *_RUNSTEP 2016-05-18 22:29:18 -07:00
step0_repl.php All step0: add test, fix bugs, remove step0 eval. 2015-03-07 09:04:07 -06:00
step1_read_print.php All step0: add test, fix bugs, remove step0 eval. 2015-03-07 09:04:07 -06:00
step2_eval.php Fix empty list eval in step2 for most languages. 2016-04-02 18:40:49 -05:00
step3_env.php php: Fix exception on literal empty list 2016-03-30 08:56:24 -04:00
step4_if_fn_do.php php: Fix exception on literal empty list 2016-03-30 08:56:24 -04:00
step5_tco.php php: Fix exception on literal empty list 2016-03-30 08:56:24 -04:00
step6_file.php load-file: accept empty file or final comment, return nil 2019-07-28 13:08:05 +02:00
step7_quote.php load-file: accept empty file or final comment, return nil 2019-07-28 13:08:05 +02:00
step8_macros.php load-file: accept empty file or final comment, return nil 2019-07-28 13:08:05 +02:00
step9_try.php load-file: accept empty file or final comment, return nil 2019-07-28 13:08:05 +02:00
stepA_mal.php load-file: accept empty file or final comment, return nil 2019-07-28 13:08:05 +02:00
types.php php: Correct a comment: SeqClass is not a parent of HashMapClass. 2019-07-07 16:58:55 +01:00
webrunner.php PHP: refactor web running mechanism. 2018-06-24 19:45:29 +08:00

Running .mal scripts on PHP hosting

Create a symlink to mal-web.php with the same name as your .mal script and your script will be executed as if it was PHP.

Here's an example using local dev.

First build mal-web.php:

cd mal/php
make mal-web.php

Now you can create a web runnable mal script:

echo '(println "Hello world!")' > myscript.mal
ln -s mal-web.php myscript.php

Start a development server with php -S 0.0.0.0:8000 and then browse to http://localhost:8000/myscript.php and you should see "Hello world!" in your browser as myscript.mal is run.

You can do the same thing on live PHP web hosting by copying mal.php up and creating a symlink for each .mal file you want to be web-executable.

PHP interop

In stepA_mal.mal you can find some examples of PHP interop.

Eval PHP code:

(php* "return 7;")
7

(php* "return array(7,8,9);")
(7 8 9)

Native function call:

(php/date "Y-m-d" 0)
"1970-01-01"

Accessing PHP "superglobal" variables:

(get php/_SERVER "PHP_SELF")
"./mal"