module Ocamlua:sig
..end
type
lua_state
type
lua_value =
| |
Lua_Table of |
|||
| |
Lua_Nil |
(* | The empty value | *) |
| |
Lua_String of |
|||
| |
Lua_Number of |
(* | The numeric type in Lua. Lua does not have a separate type for integers: all numeric values are of type float (this actually depends on the compile flags used for the Lua runtime, but this library will only compile if floats are used for Lua numbers | *) |
| |
Lua_Boolean of |
|||
| |
Lua_Closure of |
(* | Values that can be shared between the Lua runtime and OCaml code | *) |
typelua_table =
(lua_value * lua_value) list
typelua_closure =
lua_value -> lua_value
val init_state : unit -> lua_state
Ocamlua.lua_state
. Each state created by this function is
completely indepedent from one another: any side effects or operations
in one state are not visible to any other state created by this
function.
Some important implementation notes that may affect how you use
the returned state: when you pass an Ocaml closure into Lua code
as an argument to Ocamlua.call
a reference to the passed closure is
saved in a hash associated with the Lua state. This hash is not
released until the Lua state itself is released, so be aware that
if you pass in several distinct closures you may experience a
stress on memory.
val load_file : lua_state -> string -> unit
load_file state fname
loads the Lua source code contained in the file
fname
and immediately evaluates it. If the loaded code returns a
value it is silently discarded.Ocamlua.No_such_file
if fname
can not be loaded by the Lua runtimeOcamlua.Syntax_error
if the code contained in fname
is not syntatically valid Lua codeOcamlua.Internal_error
if during the execution of the code loaded from fname
an internal error occursOcamlua.Runtime_error
if during the execution of the code loaded from fname
a runtime error occursval call : lua_state -> string -> lua_value list -> lua_value
call state f args
calls the function accessible via the global
name f
in the state state
with the (possibly zero) arguments
args
. The return value of this function is the value returned by
f
. If f
returns more than 1 value they are silently discarded, if
it returns 0 values then `Lua_Nil
is returned.Ocamlua.Runtime_error
if a Lua error is generated during the execution of f
or an OCaml callbaack raises an exception (see Ocamlua.Runtime_error
for details)Ocamlua.No_such_method
if f
does not exist in the global environment associated with state
Ocamlua.Internal_error
if a Lua internal error occursOcamlua.Bad_value
if f
returns a value that cannot be represented by the Ocamlua.lua_value
type.val eval_string : lua_state -> string -> unit
eval_string state code
immediately loads and executes the Lua
code in the string code
in the context of state
. Any side
effects or actions taken during the execution of code
will not
be visible to any other states. It is not possible to change the
environment of the loaded chunk. If the loaded chunk returns a value it is
silently discarded.Ocamlua.Syntax_error
if the Lua code in code
is not syntatically validOcamlua.Runtime_error
if a runtime error occurs during the execution of the loaded chunkOcamlua.Internal_error
if a Lua internal error occurs during the evaluation of the stringval table_of_list : lua_value list -> lua_value
val list_of_table : lua_table -> lua_value list
Failure
exception.type
internal_error_code =
| |
GC_metamethod of |
(* | Thrown when an error occurs during the execution of a __gc metamethod on an object. The string argument is the error message reported by the Lua runtime | *) |
| |
Err_message_handler of |
(* | Thrown when an error occurs during the execution of a user installed error handler. The string argument is the error message reported by the Lua runtime | *) |
| |
Out_of_memory |
(* | Thrown when the Lua runtime runs out of memory. In such a situation the Lua runtime does not report any error messages | *) |
exception No_such_method of string
Ocamlua.call
if the method to call does not exist. The string
argument is the name of the function that doesexception Syntax_error of string
Ocamlua.eval_string
and Ocamlua.load_file
if the Lua source
code being loaded has a syntax error. The string is the error
reported by the Lua runtimeexception Runtime_error of string
exception Internal_error of internal_error_code
Ocamlua.internal_error_code
argument.exception Bad_value
Ocamlua.lua_value
type can be represented as Lua values, up to the practical limits
of the system). There are two ways a converion may fail: when the
conversion of a value of an inconvertible type is attempted
(e.g. a coroutine thread, arbitrary userdata, etc.) or when in
the process of converting a table recurion is detected.
This exception is only thrown when a coversion error occurs when
converting a value to return back into OCaml code. When conversion
fails when attempting to call back into Ocaml code, the conversion
error is converted into a Lua error, with the string "Bad
arguments to ocaml callback".
exception No_such_file of string
Ocamlua.load_file
when the Lua cannot load code from the
given file.