lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


[http://lua-users.org/lists/lua-l/2001-01/msg00156.html]
http://lua-users.org/lists/lua-l/2000-04/msg00000.html

As writed Erik Hougaard (.../msg00001.html):
> Very nice, but ths is one of the things that I'm playing with...
> To make a table (not lua table) so all these constants would get
> replaced with their actual values on parse time, so there was no
> need for lua to do the lookup. In a application with many constants
> that should give a performance gain !

I too should like such thing. I think, this can be like following.
Lua parser has 2 tables: _Modules (key - string: module name; value - lightuserdata: pointer to structure luaL_def) and _Defs (key - string: from, value - string: to).

struct luaL_def {
  const char *from, *to;
};

Module in C may export definitions with luaL_export(lua_State *L, char *MODULENAME, struct luaL_def *expdefs); like luaL_openlib:
---{{---
struct luaL_def expdefs[] = {
  {"OPEN", "1"}, {"CLOSE", "2"}, {NULL, NULL}
};
luaL_export(L, "File", expdefs);
---}}---

Module in Lua may define, export and import all or several definitions:
---{{---
define Err = {"EMEM" = -1, "EDSK" = -2)
export Err("EMEM")  -- if not indicate definition
import File("OPEN") -- then import/export all
---}}---

Lua parser should check keywords in _Defs during parsing chunk code.
In end _Defs deleted.

Sorry for my english.