This is a little convoluted, but lets try:
这有点令人费解,但让我们尝试:
I'm integrating LUA scripting into my game engine, and I've done this in the past on win32 in an elegant way. On win32 all I did was to mark all of the functions I wanted to expose to LUA as export functions. Then, to integrate them into LUA, I'd parse the PE header of the executable, unmangle the names, parse the parameters and such, then register them with my LUA runtime. This allowed me to avoid manually registering every function individually just to expose them to LUA.
我正在将LUA脚本集成到我的游戏引擎中,我在win32上以优雅的方式完成了这个。在win32上我所做的就是将我想要暴露给LUA的所有函数标记为导出函数。然后,为了将它们集成到LUA中,我将解析可执行文件的PE头,解开名称,解析参数等,然后使用我的LUA运行时注册它们。这使我可以避免单独手动注册每个函数,只是为了将它们暴露给LUA。
Now, flash forward to today where I'm working on the iPhone. I've looked through some Unix stuff and I've gotten very close to taking a similar approach, however I'm not sure it will actually work.
现在,闪回到我今天在iPhone上工作的地方。我已经浏览了一些Unix的东西,我已经非常接近采取类似的方法,但我不确定它会真正起作用。
I'm not entirely familiar with Unix, but here is what I have so far on iPhone:
我对Unix并不完全熟悉,但这是我到目前为止在iPhone上的内容:
-
Step 1: Query for the executable path through objective-C and get the path of my app
Step 2: Use dlopen to get a handle to my app using: `dlopen(path, RTLD_NOW)`
Step 3: Use `dlsym( libraryHandle, objectName )` to attempt to get the address of a known symbol.
The above steps won't actually get me to where I want to be, but even that doesn't work. Does anyone have any experience doing this type of thing on Unix? Are there any headers or functions I can google to put me on the right track?
上面的步骤实际上并没有让我到达我想要的地方,但即使这样也行不通。有没有人有经验在Unix上做这类事情?是否有任何标题或功能我可以谷歌让我走上正轨?
Thanks;)
4 个解决方案
#1
3
iPhone does not support dynamic linking after the initital application launch. While what you want to do does not actually require linking in any new application TEXT, it would not shock me to find out that some of the dl* functions do not behave as expected.
初始应用程序启动后,iPhone不支持动态链接。虽然你想要做的事实上并不需要在任何新的应用程序TEXT中进行链接,但是如果发现某些dl *函数的行为不符合预期,我不会感到震惊。
You may be able to write some platform specific code, but I recommend using a technique developed by the various BSDs called linker sets. Bascially you annotate the functions you want to do something with (just like you currently mark them for export). Through some preprocessor magic they store the annotations, sometimes in an extra segment in the binary image, then have code that grabs that data and enumerates its. So you simply add all the functions you want into the linker set, then walk through the linker set and register all the functions in it with lua.
您可能能够编写一些特定于平台的代码,但我建议使用由各种BSD开发的称为链接器集的技术。基本上,您可以注释要执行某些操作的函数(就像您当前将它们标记为导出一样)。通过一些预处理器魔术,它们存储注释,有时在二进制图像中的额外段中,然后具有抓取该数据并枚举其数据的代码。因此,您只需将所需的所有函数添加到链接器集中,然后遍历链接器集并使用lua注册其中的所有函数。
I know people have gotten this stuff up and running on Windows and Linux, I have used it on Mac OS X and various *BSDs. I am linking the FreeBSD linker_set implementation, but I have not personally seen the Windows implementation.
我知道人们已经在Windows和Linux上运行并运行了这些东西,我在Mac OS X和各种* BSD上使用过它。我正在链接FreeBSD的linker_set实现,但我没有亲自看过Windows的实现。
#2
0
You need to pass --export-dynamic
to the linker (via -Wl,--export-dynamic
).
您需要将--export-dynamic传递给链接器(通过-Wl, - export-dynamic)。
Note: This is for Linux, but could be a starting point for your search.
注意:这适用于Linux,但可以作为搜索的起点。
References:
#3
0
If static linking is an option, integrate that into the linker script. Before linking, do "nm" on all object files, extract the global symbols, and generate a C file containing a (preferably sorted/hashed) mapping of all symbol names to symbol values:
如果静态链接是一个选项,请将其集成到链接描述文件中。在链接之前,对所有目标文件执行“nm”,提取全局符号,并生成包含所有符号名称到符号值的(最好是有序/散列)映射的C文件:
struct symbol{ char* name; void * value } symbols = [
{"foo", foo},
{"bar", bar},
...
{0,0}};
If you want to be selective in what you expose, it might be easiest to implement a naming schema, e.g. prefixing all functions/methods with Lua_.
如果您希望对所公开的内容有所选择,那么实现命名方案可能最简单,例如:使用Lua_为所有函数/方法添加前缀。
Alternatively, you can create a trivial macro,
或者,您可以创建一个简单的宏,
#define ForLua(X) X
and then grep the sources for ForLua, to select the symbols that you want to incorporate.
然后grep ForLua的源代码,选择要合并的符号。
#4
0
You could just generate a mapfile and use that instead, no?
您可以生成一个mapfile并使用它,不是吗?
#1
3
iPhone does not support dynamic linking after the initital application launch. While what you want to do does not actually require linking in any new application TEXT, it would not shock me to find out that some of the dl* functions do not behave as expected.
初始应用程序启动后,iPhone不支持动态链接。虽然你想要做的事实上并不需要在任何新的应用程序TEXT中进行链接,但是如果发现某些dl *函数的行为不符合预期,我不会感到震惊。
You may be able to write some platform specific code, but I recommend using a technique developed by the various BSDs called linker sets. Bascially you annotate the functions you want to do something with (just like you currently mark them for export). Through some preprocessor magic they store the annotations, sometimes in an extra segment in the binary image, then have code that grabs that data and enumerates its. So you simply add all the functions you want into the linker set, then walk through the linker set and register all the functions in it with lua.
您可能能够编写一些特定于平台的代码,但我建议使用由各种BSD开发的称为链接器集的技术。基本上,您可以注释要执行某些操作的函数(就像您当前将它们标记为导出一样)。通过一些预处理器魔术,它们存储注释,有时在二进制图像中的额外段中,然后具有抓取该数据并枚举其数据的代码。因此,您只需将所需的所有函数添加到链接器集中,然后遍历链接器集并使用lua注册其中的所有函数。
I know people have gotten this stuff up and running on Windows and Linux, I have used it on Mac OS X and various *BSDs. I am linking the FreeBSD linker_set implementation, but I have not personally seen the Windows implementation.
我知道人们已经在Windows和Linux上运行并运行了这些东西,我在Mac OS X和各种* BSD上使用过它。我正在链接FreeBSD的linker_set实现,但我没有亲自看过Windows的实现。
#2
0
You need to pass --export-dynamic
to the linker (via -Wl,--export-dynamic
).
您需要将--export-dynamic传递给链接器(通过-Wl, - export-dynamic)。
Note: This is for Linux, but could be a starting point for your search.
注意:这适用于Linux,但可以作为搜索的起点。
References:
#3
0
If static linking is an option, integrate that into the linker script. Before linking, do "nm" on all object files, extract the global symbols, and generate a C file containing a (preferably sorted/hashed) mapping of all symbol names to symbol values:
如果静态链接是一个选项,请将其集成到链接描述文件中。在链接之前,对所有目标文件执行“nm”,提取全局符号,并生成包含所有符号名称到符号值的(最好是有序/散列)映射的C文件:
struct symbol{ char* name; void * value } symbols = [
{"foo", foo},
{"bar", bar},
...
{0,0}};
If you want to be selective in what you expose, it might be easiest to implement a naming schema, e.g. prefixing all functions/methods with Lua_.
如果您希望对所公开的内容有所选择,那么实现命名方案可能最简单,例如:使用Lua_为所有函数/方法添加前缀。
Alternatively, you can create a trivial macro,
或者,您可以创建一个简单的宏,
#define ForLua(X) X
and then grep the sources for ForLua, to select the symbols that you want to incorporate.
然后grep ForLua的源代码,选择要合并的符号。
#4
0
You could just generate a mapfile and use that instead, no?
您可以生成一个mapfile并使用它,不是吗?