I decided it was best to generalize my plugin so that it just sent keyboard events to Lua. This way programmers gets to interpret the events however they want.
@Caroline, you mentioned you had to print the stack to see what was going on. I have this stackDump() function that I got from PIL, but it only prints types. Do you have anything better?
I've got it all working except my event dispatching isn't working. I've read the Ultimate Guide on plugins. I've read some of the Programing In Lua book sections on C. Can anyone help me figure out what I've done wrong?
Also,
@Caroline, you mentioned in my thread on the iCadePlugin that I needed to put dispatchEvent inside of the C++ class. I actually got the idea to put eventDispatch at the top from storeKit.mm. And from what I understand, it should work. Although I don't understand why one needs a class that inherits from GEventDispatcherProxy, so I could totally be wrong.
I did do a little goofing around and in my Lua file I redefined Event.new() and put an io.write() command in it and it runs, so I know I'm creating a new event in my dispatchEvent function. And I believe lua_pcall() is even executing successfully.
I'm on my iPad so I can't upload a file, and it wont let me post the full code in one message, so I'll split this over a few posts.
Edited to remove the code. See it in the attachment below.
Comments
And here is the Lua file. It toggles the keyboard on and off every 4 seconds. Feedback is written to the Xcode console (and so far is coming from the plugin, not the Lua code). None of the Lua event handlers are getting called.
My apps: http://www.yummyyellow.com
Edit: I've updated the file.
My apps: http://www.yummyyellow.com
I'll have a fumble with your code until Atilim leaps in and sorts it out in a blinding flash.
You're just trying to show/hide the keyboard, nothing else right?
Lua code I'm using:
As for tracking, I tend to use stackdump as you have it and NSLog to print out to the Xcode console.
(Edited to update code.)
To format your code like mine, do
< pre lang="lua" >code here< /pre >
(without the spaces before and after the "<" and ">")
I think, and this is where I can't put it into technical words because I am new to Events, that the reason your Lua code didn't work and mine does, is because you are dispatching an event using the KeyInput class, and trying to catch it using the stage class.
This code altered from the code in the documentation illustrates this:
My apps: http://www.yummyyellow.com
I'd be interested your opinions and suggestions on this.
My apps: http://www.yummyyellow.com
My apps: http://www.yummyyellow.com
Not sure that this is a good solution for what @Magnusviri suggested though.
Right now when I download Gideros it comes with a lot of examples. I would like to same ease of use with community code. I don't want to go to multiple websites to get the code. I'd like to just go to one page and see a list and even be able to download it all.
However, with the Gideros sample code, if there is a change that needs to be made, you guys make those changes and they are released in the next version. There's no way that you or anyone else could try to keep track of all community changes. It needs to be automated.
That's why I like the idea of a tag on github or something. I just searched github for "gideros" and found 4 projects.
https://github.com/search?utf8=✓&q=gideros&type=Everything&repo=&langOverride=&start_value=1
Anyway, I don't think this is a really serious issue but it would certainly be nice to be able to keep up to date with what other community members do. For example, I know that the TNT Particle engine was just modified. If I got busy doing some other project I probably wouldn't have the time to keep up on the forums and I would have missed that. I also know that it's very time consuming to try to find all of the community code. I have made a strong effort and I still feel like I'm missing something.
And ok, while I'm at it, it would be nice if we did keep track of community code because I seriously see that the community is filling in a lot of missing pieces of Gideros, for example, this KeyInput plugin. To me, this plugin should simply be a part of Gideros, but how would you manage that? And right now it's iOS only. To add it officially, it should have a comparable Android version, and I can't write it because I don't know the first thing about Android (and I don't really have the time to learn it), but I don't want to put the burden on anyone else to write it. So it probably shouldn't be an official plugin until it has the Android support, which could be a long time, who knows.
Etc etc etc, anyway. I just think some way of keeping track of all of the community additions would be nice but without putting a burden on anyone to manage it.
When I get my KeyInput plugin to a state I feel like putting on the internet somewhere, I'll see about putting it on GitHub and using some sort of tag there. Then I'll start to know what GitHub can do.
My apps: http://www.yummyyellow.com
application:setOrientation(Application.LANDSCAPE_LEFT)
Then the Gideros content is landscape but the keyboard isn't. I'm not sure what to do about it. I need to get some other stuff done and I don't plan on showing the keyboard anyway, so I don't need to worry about this for now. I don't have any autorotation stuff set, so maybe that's the problem.
My apps: http://www.yummyyellow.com
Edit to add: the reason I was confused was because I know that touch events go to all sprites. But I think I was looking at it backwards. Event listeners aren't added to the thing that you want to listen, they are added to the thing that generates the event.
Edit to add more: I also have no idea why Event.ENTER_FRAME can be added to anything.
My apps: http://www.yummyyellow.com
It seems to me that user-defined events aren't broadcast globally, only to the instance that broadcast it. As in the ClassA/B example I posted above.
However, to contradict that, the Sprite example on this page:
http://www.giderosmobile.com/documentation/events.html
works, so I can only assume that user defined classes are different from Gideros defined classes in some way.
keyinput received the event, because keyinput was what broadcast it.
I never got back to github. Instead I got this done lol...
(Edit to fix typos, and add examples)
My apps: http://www.yummyyellow.com
Ok, I was thinking of putting this online somewhere central and so I looked at github and do they charge to host files? I thought they were more like sourceforge (free afaik). Anyway, if they charge, then that is obviously out (for me anyway). Otherwise I'll just put this on my webpage I guess. Maybe we can have a list on the Gideros wiki with links to all of the community code webpages? I don't know.
My apps: http://www.yummyyellow.com
Your idea to provide a list of plugins & community code is nice. I'll take care of this in the near future - or better - if there's someone who can open up a page in wiki to fill in, I can help too
http://mac.github.com/
Edit to add, here:
http://www.giderosmobile.com/forum/discussion/769/is-it-possible-to-include-some-community-contributions-with-the-official-gideros-release
My apps: http://www.yummyyellow.com
If native widgets would be available (ie textfield), would the android OS automatically show the keyboard if the textfield widget would get focused?
EIDT: I may go with virtual keyboard route, this could be easier and not that bad (and would work cross-platform). I am attaching a "virtual keyboard" file to emulate hardware buttons. Usage: just add this file to Example/Hardware/Keyboard and click the red box to test. Then it is easy to test it with Gideros Player on a desktop. I will make it full-blown keyboard some day, so there will be an alternative way to type.
I have been thinking about what to do if someone did something similar and I don't think there should be an iOS version and an Android version that have different interfaces. So whatever is done, I think they should be made identical if possible and if they are different then I should name mine ioskeyinput or something.
When I say they should be identical, I mean that this should work for both:
My apps: http://www.yummyyellow.com