lua-users home
lua-l archive

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




On 2018-02-25 10:58 PM, Sean Conner wrote:
It was thus said that the Great Soni They/Them L. once stated:
On 2018-02-25 04:51 PM, Sean Conner wrote:

Are there cases of static linking where you can't just change the symbol
names?
   Well, you can change the name in the source code (more portable, probably
the "easiest" way).  Changing the name after you have object code is ... I
don't know.  If you can, it's most likely very system dependent.


I assume static linking relies on dlopen(NULL, ...)/the global symbol table. This means the symbol must be exported anyway, which does make it trivial to rename it, as far as I know.

I assume all other cases would have to be directly embedded in the Lua source somehow. (I believe the procedure for this is described somewhere, something to do with modifying luaL_openlibs?)

   It does appear that Lua 5.3 also passes in the path (as the second Lua
parameter) to each searcher, so either the documenation is wrong, or it's
an undocumted feature.
$ lua
Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
package.preload.hello = print
require "hello"
hello    nil
   And if you read the entire section you would see this behavior documented.
I didn't quote the entire section (I apologize if I gave the impression I
did).

true
io.open("world.lua", "w"):write("print (...)"):close()
true
require "world"
world    ./world.lua
true
-- can't test a C module here but w/e, what happens if you print the
C stack from a C module?
   I'll assume you mean the Lua stack from a C lua function.  So here you go:

	#include <stdio.h>
	#include <lua.h>
	#include <lauxlib.h>
	
	int luaopen_cmod(lua_State *L)
	{
	  int max = lua_gettop(L);
	  int i;
	
	  for (i = 1 ; i <= max ; i++)
	  {
	    char const *name;
	    char const *type;
	    int         ri;
	
	    lua_getglobal(L,"tostring");
	    lua_pushvalue(L,i);
	    lua_call(L,1,1);
	
	    name = lua_tostring(L,-1);
	    type = luaL_typename(L,i);
	    ri   = i - max - 1;
	
	    printf("Stack: %d %d - %s %s\n",i,ri,type,name);
	    lua_pop(L,1);
	  }
	
	  lua_pushboolean(L,1);
	  return 1;
	}

	[spc]lucy:/tmp>lua-53
	Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
	> require "cmod"
	Stack: 1 -2 - string cmod
	Stack: 2 -1 - string ./cmod.so
	true
	>

   Answers your question?

   -spc



Interesting. So C modules could be renameable if they supported what I proposed.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.