Re: Ocaml scripting

This is a discussion on Re: Ocaml scripting within the ml forums in Programming Languages category; sheath@mail.com (Simon H.) writes: > Okay. I'm building a text-adventure engine in Ocaml, and basically, I > want certain features to be scriptable. Like, the game-writer can > write a function to trigger an event when certain criteria are met. > This, of course, means that it has to be able to load and /evaluate/ > text files, returning an Ocaml function. Of course I could write my > own interpreter and mini-scripting language, but that seems a little > like overkill since it's gonna have a total of maybe two dozen > functions. > > Now, a wholly interpreted ...

Go Back   Application Development Forum > Programming Languages > ml

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 07-08-2003, 11:10 AM
Jacques Garrigue
Guest
 
Default Re: Ocaml scripting

sheath@mail.com (Simon H.) writes:

> Okay. I'm building a text-adventure engine in Ocaml, and basically, I
> want certain features to be scriptable. Like, the game-writer can
> write a function to trigger an event when certain criteria are met.
> This, of course, means that it has to be able to load and /evaluate/
> text files, returning an Ocaml function. Of course I could write my
> own interpreter and mini-scripting language, but that seems a little
> like overkill since it's gonna have a total of maybe two dozen
> functions.
>
> Now, a wholly interpreted language like Lisp or Python comes with an
> "eval" function, which would do exactly what I want, but OCaml is
> compiled and doesn't have an equivilant, as far as I can find. The
> closest thing I can think of would be ocamlmktop, and using that would
> just make things rather more complicated than I would like to deal
> with, what with having to hack the new toplevel into acting like a
> game engine instead of a toplevel.
>
> So is there some nice easy way to do this, or shall I start writing an
> interpreter?


Well, true enough, you can already use the Dynlink library to
dynamically load ocaml bytecode into a running program. You could also
include the compiler in your application to do the compilation on the
fly: much more tricky, and not supported. Moreover, read the ocaml
license: including compiler sources puts you under the the QPL, which
is a very restrictive open-source license.

And, ocaml as a language is not at all conceived as a scripting
language: lots of errors at compile time, no handling of dynamic types,
etc...

So, do yourself a favor: it is so incredibly easy to write a small
interpreter in ocaml! Choose your tools: ocamlex/ocamlyacc or
Genlex/stream parsers (this last may be simpler). Then the interpreter
itself is simply trivial.

Still, I sometimes think that it would be nice to have a standard
scripting language for caml. Ideally, this would be just the core of a
language, and could be extended easily for customization.

---------------------------------------------------------------------------
Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp
<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 04:03 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.