Help with Modules

I’m using the tabbar viewcontroller from the community submitted code and its working well and I’m building an RSS reader app.

I have 4 screens, screen1.lua … screen4.lua.

Prior to today, I had the rss parsing code in each screen file. This is a lot of repeating myself and not very DRY, so I pulled the rss code out and made an rss.lua module (which I hope to contribute back to the whole)

Basically you call it as such:

local rss = require(rss)

then in the oncomplete callback from the network.download() api call, I do a:

stories = rss.feed(“index.rss”,system.TemporaryDirectory)

and in theory, stories holds the stories from the feed and I can take that information and load up a tableView with it.

This is all working … for screen1.lua. screen2, screen3 and screen4, contain the exact same code, but I get this error:

Runtime error
/Users/rmiracle/Lua/tACKY Project/tACKY/screen3.lua:68: attempt to call field ‘feed’ (a table value)
stack traceback:
[C]: in function ‘feed’
/Users/rmiracle/Lua/tACKY Project/tACKY/screen3.lua:68: in function

Its almost like I’m not allowed to require the same module in screen2-4 though I can in screen1.

Should I load it in main.lua and not make it local so its only loaded once?

[import]uid: 19626 topic_id: 13575 reply_id: 313575[/import]

In the infamous words of Emily Latilla (Saturday Night Live Gilda Radner character)

“Never mind”

I found the problem.

The rss.lua file’s main function was named “feed” and I was using a non-local variable called “feed” that the XML code returned its data too, probably blowing away my function reference after the first run.

Gotta watch leaving “local” off of things and using the same name for functions and variables. [import]uid: 19626 topic_id: 13575 reply_id: 49832[/import]

Sounds like a really interesting app you’re working on, Rob :slight_smile:

Well done on getting it sorted. [import]uid: 52491 topic_id: 13575 reply_id: 49877[/import]

I’m frustrated by a few things, but once I work through them it will be pretty slick.

Basically he has a wordpress blog and I’ve got him using categories finally, so I have 4 buttons in the tabBar controller: News, Podcasts, Albums (Reviews), Live (Music). The app opens by fetching the feed for the News category and puts the results in a widget.tableView. Tapping the item brings up a page where you can read the full story. If you tap on podcasts, I’m making the assumption that there will be an MP3 to play, so I show the text bits, and provide a play button, which uses media.playVideo() to stream the podcast.

Where I’m running into a bit of a problem now is on the Album Reviews, I can get the MP3’s linked to the story and provide play buttons for them, but the RSS feed doesn’t provide me any text bits to display beside the play button (like track name). So I may have to scrap that idea.

My other headache comes from trying to display big blocks of text. native.newTextBox() works pretty well but doesn’t format the embedded HTML. Making webpopup’s work requires some hackish code. I’m thinking of just using native.newTextBox() and then give the readers a link to view the article in Safari.

[import]uid: 19626 topic_id: 13575 reply_id: 49929[/import]

How did you get the tabBar to work with widgets?

When I used widget + tabBar the text on the tabs were looking like crap on Retina devices, text got scaled the crap out.

Then I changed the ui.lua that comes with that sample so it would be in Retina to the enhanced ui.lua version and modified the viewController but widget still messed up the tab text and the. The offset also got messed up so finally I started to test if it would work with widget.newButton and widget.newEmbossedText instead but that totally messed everything up so I chucked it in the trash.

So after that I decided not to mix widgets with other libraries because it was giving me some serious headaches…

But I see there’s tabBar images included with the widget sample so I’ll see if I can hack out a tabBar with the widgets, (if they included it in the latest build…)

Did you modify the viewController? [import]uid: 13560 topic_id: 13575 reply_id: 49958[/import]

I haven’t solved the text scaling problem yet. Funny though, it looks fine in the XCode simulator.

[import]uid: 19626 topic_id: 13575 reply_id: 49967[/import]

Okay I’ve fixed it. I <3 nasty hacks.

I don’t know why the tabBar controller is blowing out the size, but there was a post a while back that rewrite display.newText() to provide retina graphics. I took that logic and basically “undid” it.

In the ui.lua file that goes with the tabbar controller in the setText method, I replaced and added this code:

[lua] local xScale, yScale = display.contentScaleX, display.contentScaleY
local sizeMultiply = 1
if xScale < 1.0 or yScale < 1.0 then
sizeMultiply = 0.5
end
labelText = display.newText( newText, 0, 0, font, size * sizeMultiply)[/lua]

In the Retina text block I stole this from, sizeMultiply was set to 2.0 to scale up text to Retina quality, but whatever is causing the UI to scale up, this basically undoes it. [import]uid: 19626 topic_id: 13575 reply_id: 49973[/import]

@rob,

so you have not changed the viewController at all?

The strange part is that just by require the widgets mess everything up, I never ran the test on xcode simulator but I built for iphone4 and it was all messed up.

I was hoping to see tabBar in the widgets after the Big release but I guess it’s not ready for beta yet.

But if I understand you correctly, everything in your app is Hi-Res but the tabBar?

If you try calling
[lua]newTabBar = widget.newTabBar [/lua]
it does not cause an error so it’s there but what are the params for it??

I’m gonna try a few things, if I figure it out I’ll share it. [import]uid: 13560 topic_id: 13575 reply_id: 49974[/import]

Well I made changes to viewController.lua to try and fix it, but they didn’t work so I backed them out.

I guess I’ve not been clear, I am not building this for Retina graphics. Everything is based on the original 320x480 platform. I may fiddle with that later, but as for now I’m not.

I temporarily dropped the Retina version of display.newText() into my code and everything doubled in size, so its like widget.* already has Retina Text built in using the scale multiplier. Then the tabbar widget in the community code’s ui.lua isn’t expecting it. [import]uid: 19626 topic_id: 13575 reply_id: 49977[/import]

Hi Rob - I know this is really unrelated to this thread but you seem to know a fair amount about getting corona to talk to wordpress. I’m a wordpress developer but very new to corona. I have a site that has a front end form which creates a post and allows the user to upload and image. I’m trying to figure out where to start to turn this into an app. Any input would be greatly appreciated. Thanks! [import]uid: 15797 topic_id: 13575 reply_id: 53825[/import]

Well I would look into XML-RPC or the Atom publishing protocal. I’ve not done either, but in principle, you would use Corona to input the post, maybe grab a photo from the photo library and then upload from there using the network.request.

[import]uid: 19626 topic_id: 13575 reply_id: 53830[/import]