I am trying to use Lua on the iPhone. On Mac OS X, in a normal (non-iOS) Cocoa application, I used the following code:
lua_State* l;
l = lua_open();
luaL_openlibs(l);
luaL_loadstring(l, "print(\"Hi from Lua\");");
lua_pcall(l, 0, 0, 0);
I downloaded Lua 5.1.4 from lua.org/ftp and compiled it for Mac OS X.
In the Xcode project, I used "Add Existing Framework" to add liblua.a and I used "Add Existing Files" to add the include directory.
This works as expected, and prints the string: "Hi from Lua".
When I try the same thing in an iOS project, it gives the errors:
"_luaL_newstate", referenced from:
_main in main.o
more of the same thing...
symbol(s) not found
collect2: ld returned 1 exit status
It seems that the .a file is not linked into the iPhone app.
Does anybody know how to make this work?
(By the way, I don't really care that Apple might not accept my app if it has Lua in it.)
You'll need to compile the Lua .a for ARM, not Intel. If the Lua library uses autoconf, you can use my favorite iphone/autoconf builder: build_for_iphoneos. If it's not autoconf, then you can use that script to get an idea of how to attack it. Sometimes you can just build a Static Library Xcode project, dump all the files into it and hit build. If the build is simple enough, it'll do most of the work for you.
I know it doesn't matter for your use, but Lua-based tools are generally shippable on the app store. You just can't download arbitrary code at run time and interpret it.
You might want to check out iPhone Wax. It is a lua/iPhone bridge that lets you write native iPhone apps in pure lua! Here is a pretty good tutorial about it.
If you want to write Lua code for iOS, then check out MOAI immediately: http://getmoai.com/
Its an absolutely enjoyable framework for developing games on iOS and Android, as well as Windows and OSX. Not only that, but it provides a pretty good idea of how to properly implement a Lua-VM based hosting environment for scripting in a cross-platform manner: from MOAI, you can learn a lot about this. I've done 4 titles with MOAI so far, and won't be stopping any time soon .. MOAI absolutely kicks ass!
Also check out LOAD81, which is a similar effort albeit with SDL as the target environment: http://github.com/antirez/load81
(I've contributed a little to the LOAD81 project, specifically giving it features of interest/value to the OpenPandora community. MOAI is more commercial, LOAD81 more hobbyist..)
For those trying to learn Lua and the different methods of integrating the Lua VM in a project for multiple platform targets, both MOAI and LOAD81 can provide a lot of great background and clues about the right way to proceed.
Related
Currently we can access a particular module in Swift by command + clicking a particular Swift type. Is there a way to easily access all Swift modules / standard libraries from within Xcode?
Is there a way to debug into Swift source code like one can in Android?
Is there a way to debug into Swift source code like one can in Android?
The answer depends on what you mean by "all Swift modules / standard libraries".
If you are interested in the Swift's standard libraries (i.e. clases like String or Array), then Swift was open-sourced by Apple and you can find sources on github following links from https://swift.org/source-code/. Still there seems to be no way to "attach" those sources to navigate there from your XCode project.
However, if you are interested in most of the MacOS or iOS frameworks such as UIKit and many others, then I believe the answer is NO.
Unlike Android, iOS is a proprietary closed source OS and in most of the areas Apple has no intentions to share its code with everyone.
Side Note: Once it was claimed that one of major reasons for Apple to switch its tools from GCC stack to Clang/LLVM stack was that GCC is licensed under "copyleft" GPL and thus Apple couldn't integrate parts of GCC Obj-C backend (such as code analysis or stuff useful for refactoring) into XCode even if those parts were developed by Apple itself without making whole XCode open source. Clang/LLVM on the other hand uses more permissive open-source license that allows such 3rd-party usages.
Moreover much of the Apple's internal code still must be in Objective-C or even plain C rather than Swift. It is relatively easy to convert "headers" i.e. interfaces specification from Obj-C to Swift automatically but it is very hard for real implementation especially given difference between Obj-C and Swift. So even if it was an open-source, there would be no debugging in Swift.
On a positive side: some code gets executed and Apple can't hide it and thus you can debug it. The only problem is that the code is in machine language helpfully decoded into Assembly (x86 or ARM) by XCode. However, it obviously requires some skill and time to understand any non-trivial logic from that. And beware that you probably can't copy logic found that way without violating some copyright laws.
Swift is open source. So you can get its code and modules here.
However, you can't do it with command + clicking in Xcode from your own project. In fact, the code you got from command + clicking was not Swift source. They were headers that were generated by the compiler automatically. Those headers may be generated from Swift source code, or even Objective-C code.
Also, even though you can get source code and edit it, you can't use it on your app that you want to be published to App Store. You can only use the Swift comes with Xcode to published to App Store, or your app will be rejected.
I want to make a Fortran editor in iPhone. User can code with Fortran in an iOS app and are also able to run that code on iPhone.
Can anyone guide me with correct approach?
I had a look to the gFortran, but its not available for ARM architecture.
Thankyou..
Apple doesn't allow for compilers or interpreters on the iPhone, but there technically isn't any reason you can't setup a server based compiler, that also allows users to run their compiled apps. In fact, there are multiple sites that already do just this, but it wouldnt be a good idea to write an app that points to their site or uses their services; you would need to setup your own service.
Not insurmountable, but I would move onto other app ideas.
Given Apple's snarly attitude about language interpreters running under iOS you're better off coding this as service that runs on a remote server, maybe with the editing part on the phone or tablet.
Updating this old thread for the sake of current and future searches:
Apple has changed their attitude over the past year or so. There are currently many interpreters available for iOS, including for Lua (https://itunes.apple.com/us/app/iluabox/id398073834?mt=8) and several for Python (https://itunes.apple.com/us/app/python-2.7-for-ios/id485729872?mt=8, http://itunes.com/apps/pythonmath).
One significant remaining restriction is that these apps may not load scripts from outside the app, for example, from Dropbox or iTunes file sharing. (This is part of Apple's efforts -- along with code signing and 100% app review -- to minimize malware.) Such apps are allowed to have an editor that allows the user to copy and paste code into the editor from outside the app.
As far as I know, there aren't any apps for compiled languages such as FORTRAN.
Meanwhile, FORTRAN compiler is available for iOS only as a jailbroken application.
[Disclaimer: I am the author of Python Math. Apple removed it from the store for a short time until I removed iTunes file sharing and "Open In..." capability. I then added a script editor.]
Is there any MacOS virtual machine that can run on PC?
Is there any source to get it?
What is the best way to develop apps for iphone?
Yes all the developer tools are OSX only.
There are lots of iPhone development books out there go check out amazon and find one with some good reviews and that will get you started.
You might not, in the strictest terms, have to get a Mac to develop for iPhone; but it will be extremely helpful. Apple is relatively talented at squashing efforts directed towards Hackintoshes and virtual machines running OS X.
The shortest answer that will give you the least hassle is: Yes you need a Mac.
But, as far as I know there are a few possibilites, that try to reimplement some Cocoa Frameworks (however they might be Mac OS X only and not iPhone): GNUStep is an example.
But I don't think you get something aquivalent to Xcode (the IDE for iPhone development) this way.
And I think there are some OSX86 Virtual Machines (however these seem to be against Apple's EULA and thus seem to be clearly illegal so I won't point you anywhere to get them).
So to conclude - if you want to develop for iPhone: getting a Mac is the easiest way, even though not cheap.
Hope this helps.
The short answer is - yes.
One possibility for learning some of what you need to know before getting a Mac is GNUstep.
However, GNUstep is mainly useful for learning Objective C, especially since it provides many of the classes that the Cocoa toolkit for iPhone does. This can be run on Windows.
It doesn't, however, support some of the key 2.0 language features that are used 'all the time' in any sample code.
What it will allow you to do is design a UI using their UI designer GORM, and use a near-identical message-based system for implementing a UI, and you could theoretically write Objective C classes in GNUstep and then use them on iPhone.
However, to compile an app for iPhone you basically need to have a Mac, because then you can get the key for signing an app, etc. Since you need to get a Mac at some point, there's really little point in going the much harder route of using GNUstep first and learning a more limited implementation, unless you really need to get started before funds are available.
Despite the new SDK terms that can other programming languages, if you're really wanting to start without a Mac, I'd probably be tempted to look at something like Unity, or perhaps even Appcelerator Titanium, and figuring out all the non-platform-specific logic first on whatever platform (Unity has a free version that can be run on Windows, for example).
I'm not that big a fan of xcode, but is is far and a way the best IDE for Objective C development simply because there's almost nothing else out there.
There are, as always, other options. If you do a web app type project, you can implement the website and test a lot of it in a browser. Furthermore, since Android and iPhone browsers are both WebKit based, you can use the free Android SDK to see what pages look like on a comparable mobile device. And since you can use C and C++ classes as well as Objective C (N.B. not for the GUI, since that needs the Objective C extensions for messaging between objects), another option for making a start without a Mac would be to use Eclipse, QT Creator or some other C/C++ IDE to implement non-GUI classes, so long as you make sure you don't use platform-specific libraries.
But the end of the long answer is still that whatever you do, to compile a proper iPhone app you'll be using xcode and associated tools to finally build it and sign it, and so you need a Mac in the end. If you want to create something targetting the iPhone and won't have access to a Mac, then perhaps you're best off looking at creating an iPhone-adapted website using iui or a similar toolkit to give the site a suitable look and feel.
Is it possible to create an own obj-C Cocoa Touch framework which can be used by other developers? And furthermore can you protect this framework?
I've created templates for Xcode 4 that allow you to build universal iOS frameworks (which work in both device and simulator).
Once the templates are installed, you simply select "Static iOS Framework" when creating a new project and it does the rest. It also works with unit tests.
https://github.com/kstenerud/iOS-Universal-Framework
You can create a static library. There is an option in the XCode project chooser to do this. You'll have to distribute the compiled static library file and the header files to users of your library. Your actual implementation files (.m) do not need to be distributed.
GHUnit does a good job of this - packaging up the libraries for both simulator and device - so I recommend looking at this project. (I also recommend using this library for unit testing :-)
The frameworks in Objective C are typically just C / ObjC code and a bunch of classes, nothing amazingly special. As such, you can create your own if you'd like, and then just include that in your project when you build it. The iPhone doesn't care about the difference, it just knows to put all that code into your app, along with everything else.
Have a look at the Framework Programming Guide on Apple's website. It will get you started. Essentially what you'll do is create a Framework project in XCode and then go from there.
As for "protecting" your framework, I assume you mean making your code unreadable. I'm not sure if and how you can do this, but perhaps Apple's guide will say something about it.
Yes you can create frameworks for use with Cocoa Touch.
However there are these caveats:
has to be a statically linked libary, no dynamic loading (dyld) for us
should be a combined (lipo) library for i386 (simulator), arm6 and arm7
you need to hack a bundle project into a framework
you should embed (small and few) images into the library so that the developer does not have to mess around with resources but just drags/drops it into his project
... or if you have large and many images build a bundle with these
I have guides for these things on my site.
1+2 = http://www.drobnik.com/touch/2010/04/universal-static-libraries/
The other links you have to google because this site does not let me post more than one URL.
You could make a static library available as binary (i.e. rudimentary "protection") to third parties, but not a dynamic one, as Apple's App Store policy prevents dynamic linking.
Take a look at a worked example for static libraries given at
this site
If you're going to do it, in my opinion JSON.framework is a great example to follow. To hide/obfuscate the source code is a different story, and a different question entirely,
When creating a new project, navigate to iOS > Framework & Library > Cocoa Touch Framework, it's as simple as that. When you are successfully compile, .framework will be created under Products folder in XCode. Right click to show in Finder, and you can find the output.
It's unlikely this will work the way you want it to because the other developers won't be able to use your framework. This StackOverflow Question explains why.
I'm going to do something I never thought I'd do... learn how to program for Apple hardware . After working in C, C++, C#, .NET, and even in the golden days of DOS (a little DOS4G/W memory extender in Borland Turbo-C, anyone?) and even as a kid, playing around with Atari 8-Bit Turbo-BASIC, I feel a little traitorous on multiple levels :) Anyway, I'm going to grad school, studying music full-time - it'll be the first time in years I won't have a full-time programming gig - and I thought it would be fun to pick-up some Objective-C in my free-time - and maybe a little extra pocket change (one can always hope :)
So, to the point of the post. I'm very used to Visual Studio, the designer, the XAML editor, the code-behind, blah blah blah. A friend pulled up X-Code on his little MacBook to show off how cool it's supposed to be. Sure, it has the same sorts of things as VS overall, but it seemed a little more scattered then I'd like. I'm sure once I got used to it, it would be fine, but I was just wondering if there are other good, free (or almost free)/or open-source editors out there for the Intel-based Apples that could also handle iPhone development. Or any tips on getting into xCode? I've just decided to do this, so I feel like I'm starting from scratch. I'm not slamming X-Code... I haven't really used it yet. I was just wondering what coders' preferences are.
Thanks for any advice!
There really is no alternative IDE on OS X for writing native applications. Some dislike the Xcode built-in editor, however. One very popular alternative is TextMate (non-free, but well worth the ~$50). Xcode can be configured to use your editor of choice for editing text files. Free alternatives include Emacs and Vim ports for OS X.
You can, of course, use the gcc toolchain without Xcode (e.g. using one of the Unix-style build systems such as Make). You can also use xcodebuild at the terminal command line to build an Xcode project without using the Xcode GUI at all (you'd be hard-pressed to configure and manage the project without the GUI, however). Combining these two, one could cobble together an IDE from e.g Eclipse to build an OS X app. iPhone would be harder since Xcode handles certificate signing etc. for you, but still possible. You would loose all of the nice Objective-C completion and documentation integration you get from Xcode, of course.
So, in summary, Xcode is pretty much the only game in town. It will undoubtedly take a while to get used to coming from VS. In particular, code generation is almost unheard of in the Cocoa world. When you feel yourself searching for those kind of tools, train yourself to try a different approach. Objective-C's late-binding combined with the power of NIB/XIB (bundles produced in Interface Builder that describe the UI of an app; XIB is a newer, version-control-friendly XML-based format that is automatically compiled into a NIB, the old-style format from NextStep days) makes code generation unnecessary.
For non-Cocoa/iPhone development, the ecosystem is naturally larger. Nokia has their own IDE for the Qt toolkit which can be used to write OS X (but not iPhone) apps. Eclipse can be used to write Java apps using any of the Java toolkits (including SWT and the Qt-Java framework, QtJambi).
For pure Windows-developer familiarity, there's also Mono which runs on OS X. MonoDevelop may run on OS X, but I'm not sure.
I think XCode is the most popular choice amongst Cocoa developers. I think the best thing you could do is go straight into writing apps and exploring.
http://cocoadevcentral.com/ - Has some great tutorials, they're also usually very screenshot friendly.
For pure ease XCode will be the way to go since it integrates with the iPhone simulator and Interface Builder. Also, when you want to deploy your app to an actual device XCode does the certificate installation and management. I don't have experience with any other IDE's for OSX though so I can't 100% answer your question. But, these are things you'll want to be aware of during your investigation.
Let us know what you find!