Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Using plugin.utf8 in CoronaCards for iOS
Started by apps638 Sep 08 2019 08:52 AM

4 replies to this topic

Best Answer vlads , 09 September 2019 - 12:36 PM

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!
 

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

apps638

[GLOBAL: userInfoPane.html]
apps638
  • Enthusiast

  • 35 posts
  • Corona SDK

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:

 

ERROR: Runtime error
module 'plugin.utf8' not found:
no field package.preload['plugin.utf8']
no file
 
My main.lua file has this line: 
 
utf8lib = require("plugin.utf8")
 
Can anyone help me add the last few steps?
 


[TOPIC: post.html]
#2

vlads

[GLOBAL: userInfoPane.html]
vlads
  • Contributor

  • 972 posts
  • Corona Staff

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.



[TOPIC: post.html]
#3

apps638

[GLOBAL: userInfoPane.html]
apps638
  • Enthusiast

  • 35 posts
  • Corona SDK

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.



[TOPIC: post.html]
#4

vlads

[GLOBAL: userInfoPane.html]
vlads
  • Contributor

  • 972 posts
  • Corona Staff

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.



[TOPIC: post.html]
#5

vlads

[GLOBAL: userInfoPane.html]
vlads
  • Contributor

  • 972 posts
  • Corona Staff

  Best Answer

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!
 


  • apps638 likes this


[topic_controls]
[/topic_controls]