Using plugin.utf8 in CoronaCards for iOS

I’m migrating an existing codebase from Corona to CoronaCards. It relies heavily on the utf8 plugin provided by Corona. I looked at the other forum post discussing how to use plugins in CoronaCards, but I’m not sure how to integrate it.

I’ve got a copy of the libplugin.utf8.a file and I’ve added it to my Linked Frameworks and Libraries section in Xcode. What else is needed? Are there header search paths, library search paths that need to be added? How does the .a file get recognized in the lua code? How does libplugin.utf8.a become recognized in lua as require(“plugin.utf8”)?

I’m currently getting this error in the console:

[lua]ERROR: Runtime error

module ‘plugin.utf8’ not found:

no field package.preload[‘plugin.utf8’]

no file[/lua]

My main.lua file has this line: 

[lua]utf8lib = require(“plugin.utf8”)[/lua]

Can anyone help me add the last few steps?

It has to expose symbol luaload_plugin_utf8. Make sure it is not getting stripped from your code. Usually -ObjC linker flag helps. Also, make sure it is getting linked to the binary. You can check it with nm command like this:

➜ nm -gU TestApp.app/TestApp | grep luaopen\_plugin\_ 0011bd84 T \_luaopen\_plugin\_utf8 001181c6 T \_luaopen\_plugin\_zip 000000010015b9d8 T \_luaopen\_plugin\_utf8 00000001001579f4 T \_luaopen\_plugin\_zip

You can see that I got utf8 and zip linked.

I do have the -ObjC linker flag. It appears to be linking the library in the compilation process (I see a -lplugin.utf8 in the list of linked library flags). However, using the suggested

nm -gU 

command, I don’t have a _luaopen_plugin_utf8 listed. If I run the same command against the libplugin.utf8.a file I do see an entry for that symbol.

Could it be stripping it out (maybe it doesn’t think it needs it)? The project is mostly swift, modeled off the Corona Cards single view controller template here:

https://github.com/CoronaCards/sample-ios-SimpleView-swift

I appreciate the help here, I’d be quite stuck without it.

Hey!

My guess is on that it does strip the function as dead code, since linker can’t know we invoke it dynamically from the Lua code.

First, try to see if you’re getting any luaload functions: you should get some of them:

nm -gU your-app.app/your-app | grep luaopen\_

If you don’t see utf8, that it means one of two things: it is either getting stripped, or you’re not linking it. You can try turning off “Dead Code Stripping” in Xcode for your target. See if will make it appear/work. If it will, I’ll try to come up with nicer solution for you.

Hey. I figured this out. Here’s few weird tricks which will get you the plugin working:

Step 1. Open “Swift-Interoperability/CoronaCards-Bridging-Header.h” and add this line:

extern int luaopen\_plugin\_utf8(void\*);

Step 2. Anywhere in Swift, for example in ViewController.swift, inside a function add this line:

print(luaopen\_plugin\_utf8)

Step 3: enjoy your plugin!

So, note lack of the parentheses around luaopen_plugin_utf8 printing call. We’re printing function (address) not it’s result. So, Step 1 would get function declared into Swift. And Step 2 would force Swift linker to include the function so its address would be available.

You can continue adding plugins, following this template, and adding them to same print statement, like print(luaopen_plugin_utf8, luaopen_plugin_zip) etc. and adding declaration to .h file.

I just tried this method, I got everything working.

Cheers and good luck!
 

It has to expose symbol luaload_plugin_utf8. Make sure it is not getting stripped from your code. Usually -ObjC linker flag helps. Also, make sure it is getting linked to the binary. You can check it with nm command like this:

➜ nm -gU TestApp.app/TestApp | grep luaopen\_plugin\_ 0011bd84 T \_luaopen\_plugin\_utf8 001181c6 T \_luaopen\_plugin\_zip 000000010015b9d8 T \_luaopen\_plugin\_utf8 00000001001579f4 T \_luaopen\_plugin\_zip

You can see that I got utf8 and zip linked.

I do have the -ObjC linker flag. It appears to be linking the library in the compilation process (I see a -lplugin.utf8 in the list of linked library flags). However, using the suggested

nm -gU 

command, I don’t have a _luaopen_plugin_utf8 listed. If I run the same command against the libplugin.utf8.a file I do see an entry for that symbol.

Could it be stripping it out (maybe it doesn’t think it needs it)? The project is mostly swift, modeled off the Corona Cards single view controller template here:

https://github.com/CoronaCards/sample-ios-SimpleView-swift

I appreciate the help here, I’d be quite stuck without it.

Hey!

My guess is on that it does strip the function as dead code, since linker can’t know we invoke it dynamically from the Lua code.

First, try to see if you’re getting any luaload functions: you should get some of them:

nm -gU your-app.app/your-app | grep luaopen\_

If you don’t see utf8, that it means one of two things: it is either getting stripped, or you’re not linking it. You can try turning off “Dead Code Stripping” in Xcode for your target. See if will make it appear/work. If it will, I’ll try to come up with nicer solution for you.

Hey. I figured this out. Here’s few weird tricks which will get you the plugin working:

Step 1. Open “Swift-Interoperability/CoronaCards-Bridging-Header.h” and add this line:

extern int luaopen\_plugin\_utf8(void\*);

Step 2. Anywhere in Swift, for example in ViewController.swift, inside a function add this line:

print(luaopen\_plugin\_utf8)

Step 3: enjoy your plugin!

So, note lack of the parentheses around luaopen_plugin_utf8 printing call. We’re printing function (address) not it’s result. So, Step 1 would get function declared into Swift. And Step 2 would force Swift linker to include the function so its address would be available.

You can continue adding plugins, following this template, and adding them to same print statement, like print(luaopen_plugin_utf8, luaopen_plugin_zip) etc. and adding declaration to .h file.

I just tried this method, I got everything working.

Cheers and good luck!