[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Lua 4.1 Alpha and binary compilation
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Tue, 7 Aug 2001 17:38:15 -0300
>> >I thought I read once that Lua 4.1 was supposed to allow the
>> >functionality of LuaC.exe to reside in the same Lua library used by
>> >Lua.exe. Is this true? I want to binary compile (to bytecode) some
>> >scripts generated at runtime on the Xbox
>>
>> See luac/src/luac/ldumplib.c
>
>This looks like it'll work like a charm.
First, a simple correction: the file is src/luac/ldumplib.c.
And it is a tentative implementation.
Next, a clarification that may be useful to others: Lua 4.1 introduced two
new API functions: lua_loadfile and lua_loadbuffer. They are similar to
lua_dofile and lua_dobuffer, except that the chunks are not run but instead
are left on the top of the stack as ordinary functions. I think this was a
requeste maed in this list.
lua_dofile is now implemented using lua_loadfile. It's essentially
lua_dofile(L, filename):
lua_loadfile(L, filename)
lua_call(L, 0, LUA_MULTRET);
except for error handling.
lua_loadfile and lua_loadbuffer have been exported to lbaselib as loadfile
and loadstring.
The ldumplib library simply adds a function called "dump" that takes a Lua
function and converts it to a (binary) string identical to the contents of
a file created by luac.
A bare bones luac could be written in Lua as write(dump(loadfile(f))).
--lhf