<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: Times New Roman; font-size: 12pt; color: #000000'>Yes, the interface is a bit of a mess. I just threw it together so people would have something. I had planned something along the lines of:<br><br>luerl:eval(String|Chunk) -> Result.<br>luerl:dofile(String) -> Result.<br><br>Basic simple interface which initialises a state and evaluates the chunk String in it returning a list of return values (if any). For example luer:eval("local t={'a','b'} return t[1],t[2]") will return [<<"a">>,<<"b">>]. luerl:dofile/1 is not really necessary.<br><br>luerl:new() -> State.<br>luerl:eval(String|Chunk, State) -> {Result,NewState}.<br><div style="text-align: left;">luerl:dofile(String, State) -> {Result,NewState}.<br></div>luerl:compile(String) -> {ok,Chunk}.<br><br>A more complex interface. luerl:new/0 creates an initial state. luerl:eval/2 will evaluate a chunk in a state and return the values and the updated state. This state can be reused to evaluate new chunks. Again luerl:dofile/2 is not really necessary. luerl:compile(String) compiles the string into an internal form ready to run in eval/1/2.<br><br>Result is always a list of return values which may be empty if the chunk does not do a return with values. For data types:<br><br>Lua strings are binaries<br>Lua numbers are floats<br>Lua tables are orddicts (property lists) of key-value tuples<br>Lua true, false, nil are just the atoms true, false, nil<br><br>Anyway something along those lines. It might be nice to have a function call wrapper which would allow you a more erlang like way of calling a luerl function.<br><br>Robert<br><br><hr id="zwchr"><blockquote style="border-left:2px solid rgb(16, 16, 255);margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">
Regarding interface function names:<br>
<br>
I wonder what logic Luerl's names of do and eval follow:<br>
<br>
dofile/1, like eval/1, returns a pragmatic Ret <br>
<br>
while do/2 returns {String, State}<br>
<br>
Since you are exporting ps/1, there should maybe be a dochunk/2? <br>
<br>
And /1, too? <br>
<br>
Or should it maybe be evalchunk/1, dochunk/2 (the /2s with State as
second parameter)?<br>
<br>
Here are some relevant functions from Lua's C interface.<br>
<br>
<blockquote><b>luaL_dofile</b><br>
<br>
[-0, +?, m]<br>
int luaL_dofile (lua_State *L, const char *filename);<br>
Loads and runs the given file. It is defined as the following
macro:<br>
<br>
(luaL_loadfile(L, filename) || lua_pcall(L, 0, LUA_MULTRET,
0))<br>
It returns false if there are no errors or true in case of errors.<br>
<br>
<b>luaL_dostring</b><br>
<br>
[-0, +?, โ]<br>
int luaL_dostring (lua_State *L, const char *str);<br>
Loads and runs the given string. It is defined as the following
macro:<br>
<br>
(luaL_loadstring(L, str) || lua_pcall(L, 0, LUA_MULTRET, 0))<br>
It returns false if there are no errors or true in case of errors.<br>
<br>
<b>luaL_loadstring</b><br>
<br>
[-0, +1, โ]<br>
int luaL_loadstring (lua_State *L, const char *s);<br>
Loads a string as a Lua chunk. This function uses lua_load to load
the chunk in the zero-terminated string s.<br>
<br>
This function returns the same results as lua_load.<br>
<br>
Also as lua_load, this function only loads the chunk; it does not
run it.<br>
<br>
<b>luaL_newstate</b><br>
<br>
[-0, +0, โ]<br>
lua_State *luaL_newstate (void);<br>
Creates a new Lua state. It calls lua_newstate with an allocator
based on the standard C realloc function and then sets a panic
function (see ยง4.6) that prints an error message to the standard
error output in case of fatal errors.<br>
<br>
Returns the new state, or NULL if there is a memory allocation
error.<br>
</blockquote>
<br>
Source: <a class="moz-txt-link-freetext" href="http://www.lua.org/manual/5.2/manual.html" target="_blank">http://www.lua.org/manual/5.2/manual.html</a><br>
</blockquote><br></div></body></html>