misc/liblua/loadlib.c
changeset 10017 de822cd3df3a
parent 3697 d5b30d6373fc
equal deleted inserted replaced
10015:4feced261c68 10017:de822cd3df3a
    21 #include "lauxlib.h"
    21 #include "lauxlib.h"
    22 #include "lualib.h"
    22 #include "lualib.h"
    23 
    23 
    24 
    24 
    25 /* prefix for open functions in C libraries */
    25 /* prefix for open functions in C libraries */
    26 #define LUA_POF		"luaopen_"
    26 #define LUA_POF     "luaopen_"
    27 
    27 
    28 /* separator for open functions in C libraries */
    28 /* separator for open functions in C libraries */
    29 #define LUA_OFSEP	"_"
    29 #define LUA_OFSEP   "_"
    30 
    30 
    31 
    31 
    32 #define LIBPREFIX	"LOADLIB: "
    32 #define LIBPREFIX   "LOADLIB: "
    33 
    33 
    34 #define POF		LUA_POF
    34 #define POF     LUA_POF
    35 #define LIB_FAIL	"open"
    35 #define LIB_FAIL    "open"
    36 
    36 
    37 
    37 
    38 /* error codes for ll_loadfunc */
    38 /* error codes for ll_loadfunc */
    39 #define ERRLIB		1
    39 #define ERRLIB      1
    40 #define ERRFUNC		2
    40 #define ERRFUNC     2
    41 
    41 
    42 #define setprogdir(L)		((void)0)
    42 #define setprogdir(L)       ((void)0)
    43 
    43 
    44 
    44 
    45 static void ll_unloadlib (void *lib);
    45 static void ll_unloadlib (void *lib);
    46 static void *ll_load (lua_State *L, const char *path);
    46 static void *ll_load (lua_State *L, const char *path);
    47 static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym);
    47 static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym);
   151 #include <mach-o/dyld.h>
   151 #include <mach-o/dyld.h>
   152 
   152 
   153 
   153 
   154 /* Mac appends a `_' before C function names */
   154 /* Mac appends a `_' before C function names */
   155 #undef POF
   155 #undef POF
   156 #define POF	"_" LUA_POF
   156 #define POF "_" LUA_POF
   157 
   157 
   158 
   158 
   159 static void pusherror (lua_State *L) {
   159 static void pusherror (lua_State *L) {
   160   const char *err_str;
   160   const char *err_str;
   161   const char *err_file;
   161   const char *err_file;
   228 ** Fallback for other systems
   228 ** Fallback for other systems
   229 ** =======================================================
   229 ** =======================================================
   230 */
   230 */
   231 
   231 
   232 #undef LIB_FAIL
   232 #undef LIB_FAIL
   233 #define LIB_FAIL	"absent"
   233 #define LIB_FAIL    "absent"
   234 
   234 
   235 
   235 
   236 #define DLMSG	"dynamic libraries not enabled; check your Lua installation"
   236 #define DLMSG   "dynamic libraries not enabled; check your Lua installation"
   237 
   237 
   238 
   238 
   239 static void ll_unloadlib (void *lib) {
   239 static void ll_unloadlib (void *lib) {
   240   (void)lib;  /* to avoid warnings */
   240   (void)lib;  /* to avoid warnings */
   241 }
   241 }
   443   return 1;
   443   return 1;
   444 }
   444 }
   445 
   445 
   446 
   446 
   447 static const int sentinel_ = 0;
   447 static const int sentinel_ = 0;
   448 #define sentinel	((void *)&sentinel_)
   448 #define sentinel    ((void *)&sentinel_)
   449 
   449 
   450 
   450 
   451 static int ll_require (lua_State *L) {
   451 static int ll_require (lua_State *L) {
   452   const char *name = luaL_checkstring(L, 1);
   452   const char *name = luaL_checkstring(L, 1);
   453   int i;
   453   int i;
   585 /* }====================================================== */
   585 /* }====================================================== */
   586 
   586 
   587 
   587 
   588 
   588 
   589 /* auxiliary mark (for internal use) */
   589 /* auxiliary mark (for internal use) */
   590 #define AUXMARK		"\1"
   590 #define AUXMARK     "\1"
   591 
   591 
   592 static void setpath (lua_State *L, const char *fieldname, const char *envname,
   592 static void setpath (lua_State *L, const char *fieldname, const char *envname,
   593                                    const char *def) {
   593                                    const char *def) {
   594   const char *path = getenv(envname);
   594   const char *path = getenv(envname);
   595   if (path == NULL)  /* no environment variable? */
   595   if (path == NULL)  /* no environment variable? */