Shop OBEX P1 Docs P2 Docs Learn Events
Eval — Parallax Forums

Eval

codekingcodeking Posts: 39
edited 2007-01-08 22:36 in Propeller 1
Is there a function like PHP's eval in spin, where it will execute the code on a string?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-08 21:46
    No. That would require a source level interpreter which doesn't exist for spin.
    Have a look at FemtoBasic (http://forums.parallax.com/showthread.php?p=624225)
    for an example of a source level interpreter that runs on the Propeller. The source can be modified to use
    floating point rather than integer arithmetic and you could throw out everything except the expression
    parser if you only need that. This interpreter compresses keywords. If you're just handling expressions,
    you don't really need that either.
  • codekingcodeking Posts: 39
    edited 2007-01-08 22:05
    PUB main
    something(dothis(hi));

    PUB something (function)
    (somehow run the function dothis(hi))

    See what I'm saying? What that would do would dothis would be run and it's results passed on the something (function). I want the command to do the function to be passed down to something (function)
  • rokickirokicki Posts: 1,000
    edited 2007-01-08 22:14
    You want to pass essentially a function pointer, right? Or do you need a function pointer *and* values (a closure)?

    It is possible to do function pointers, but it's painful and convoluted. Chances are there's an easier way of doing what
    you intend.
  • acantostegaacantostega Posts: 105
    edited 2007-01-08 22:36
    Phipi had some examples of using function pointers, using callbacks for printing out a stream of bytes if I'm not mistaken. Try to search his posts.
    Eval (if it works like Lisp's eval) seems to be a strange way of passing a function as an argument, but I don't know php so I can't say anymore.
Sign In or Register to comment.