|
Hi Robert, To allow for String|Chunk, the chunks returned from ps/1 would have to be wrapped to be distinguishable from the Strings. I think 'functiondef' could be the right choice. For the names, I'd propose to maybe stay closer to the Lua language function names and its C interface [1]. But at any rate, to maybe decide for one of "do" and "eval" to 1) return bare results 2) return {Result, State}. Rather than making this dependent on whether State was handed in or not as a parameter? Since Lua uses dofile() both in the Lua language and the C interface, (and since of course neither case returns state), the "do" functions look earmarked for returning the simple, bare bones Result. However ... somehow "eval" is a better fit for a function that is expected to return something. Lua's C interface uses "load" for parsing-only: load, loadfile, lua_load [2], lua_loadfile, lua_loadstring, lua_loadbuffer. This could be an alternative to wrapping the chunks: for load, in Lua "the string mode controls whether the chunk can be text or binary (that is, a precompiled chunk). It may be the string "b" (only binary chunks), "t" (only text chunks), or "bt" (both binary and text). The default is "bt". [5] The type that the loads return is 'function': "If there are no syntactic errors, returns the compiled chunk as a function; otherwise, returns nil plus the error message." --- therefore, the right chunk wrapper could be { functiondef, ... }, instead of compiled chunks being lists as outermost type. Execution of pre-parsed/compiled chunks is "call": pcall, xpcall, lua_call, lua_pcall [3], and lua_pcallk. State is created and destroyed by lua_newstate and lua_close. There is no "eval" in Lua. So here's my proposal: luerl:eval(String|Chunk[, State]) -> Result. luerl:evalfile(PathString[, State]) -> Result. luerl:do(String|Chunk[, State]) -> {Result, NewState}. luerl:dofile(PathString[, State]) -> {Result, NewState}. luerl:newstate() -> State. luerl:close(State) -> ok. luerl:load(String) -> {ok, Chunk}. luerl:loadfile(PathString) -> {ok, Chunk}. luerl:call(Chunk[, State][, ErlParamList()]) -> {Result, NewState}. luerl:tolua(list()) -> LuerlTermsList(). luerl:toerlang(LuerlTermsList()) -> list(). This would be somewhat in keeping with Lua's naming. I am unclear about error state returns. Simply in the Result I guess? Relative to your proposal that is: luerl:eval(String|Chunk) -> Result. => luerl:eval(String|Chunk[, State]) -> Result. luerl:dofile(String) -> Result. => luerl:dofile(PathString[, State]) -> {Result,State}. luerl:new() -> State. (currently luerl:init() -> State.) =>luerl:newstate() -> State. luerl:eval(String|Chunk, State) -> {Result,NewState}. => luerl:eval(String|Chunk, State) -> {Result,NewState}. luerl:dofile(String, State) ->
{Result,NewState}. => same
luerl:compile(String) -> {ok,Chunk}. => luerl:load(String)
-> {ok,Chunk}.Beyond that, I had thought with 'interface' you would be addressing the direct interchange of values between Erlang and Lua. I'd be all for making the collection of tables in the Lua state accessible and writable, directly, somehow navigating into it using a key structure. And if possible, vice versa: giving Lua direct access to Erlang state. Best, Henning [1] http://www.lua.org/manual/5.2/manual.html#4.8 [2] One note I like, in the description of the C function lua_load : "The source argument gives a name to the chunk, which is used for error messages and in debug information (see §4.9)." http://www.lua.org/manual/5.2/manual.html#lua_load - http://www.lua.org/manual/5.2/manual.html#2.3 [3] When you use xpcall or lua_pcall, you may give a message handler to be called in case of errors. This function is called with the original error message and returns a new error message. It is called before the error unwinds the stack, so that it can gather more information about the error, for instance by inspecting the stack and creating a stack traceback. This message handler is still protected by the protected call; so, an error inside the message handler will call the message handler again. If this loop goes on, Lua breaks it and returns an appropriate message. - http://www.lua.org/manual/5.2/manual.html#2.3 [4] In Lua (not the C interface), dofile does not run in protected mode. http://www.lua.org/manual/5.2/manual.html#6.1 [5] http://www.lua.org/manual/5.2/manual.html#6.1 On 2/20/12 10:59 PM, Robert Virding wrote:
|