lua-users home
lua-l archive

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

2009/9/4 Andre de Leiradella <>:
> Take a look at http.lua from LuaSocket:
> -----------------------------------------------------------------------------
> -- Declare module and import dependencies
> -------------------------------------------------------------------------------
> local socket = require("socket")
> local url = require("socket.url")
> local ltn12 = require("ltn12")
> local mime = require("mime")
> local string = require("string")
> local base = _G
> local table = require("table")
> module("socket.http")
> ...
> I simply don't know how to "internalize" LuaSocket into an executable. It
> doesn't seem that executing its loader function is enough.
> Please don't get me wrong, LuaSocket is a great library, it's just that I
> don't seem to find a way to make it into my application the way I want it
> to.

LuaSocket is a perfect example where using package.preload and require
is just as simple if not simpler than trying to load everything
yourself. Just put all the LuaSocket module loaders in the preload
table. For C modules, use the luaL_preload function I gave earlier.
For the Lua modules, use luaL_loadbuffer instead of lua_pushcfunction.
I don't know how to be more explicit. Tell us if it's still not clear

I think this is simple enough. Modules, packages, or whatever you call
them have interdependencies. There is now a mechanism to express these
dependencies at runtime. All you have to do is to make the modules you
may need indirectly (you want socket.http but it needs socket.url) to
be available somehow, and between all the existing searchers and the
ones you can add there is plenty of freedome to pick what is the
simplest for you. You may be used to the old way of doing things, but
from the point of view of someone that started using Lua at the
release of 5.1, the old way doesn't look any simpler even in embedding