How do I set up a project with Xcode4? Been trying for hours

New to Moai? Get started here with our best tips and tutorials.

How do I set up a project with Xcode4? Been trying for hours

Postby SweBeat » Tue Jun 26, 2012 11:30 am

Hello,

I have searched the forum and some people seem to have gotten the answer but I feel like a complete idiot because I just don't get how to set up my own project with Xcode so I can edit stuff and for example just change the picture in the example project from the host/ios stuff. I want to develop for iOS if I forgot to mention that.

Could someone maybe give me a nice guide how to set this thing up? How to start my own project and begin coding and everything? With pictures if possible.

I have really been stuck for hours and I have googled, read everything about 100 times and I still don't manage to fix the stuff.
Maybe the reason for this is because I don't get something in the guide but I'm really really stuck.

The only thing I manged so far is to go into host/xcode/ios and get that up and running. But after that I'm stuck. I haven't gotten the sample stuff to work, or even to change the rotating picture in the host stuff. I beg if someone please could help me get started. I have experience with LUA, and games in general but this seems to get me to stuck. I really can't get anywhere. :?
SweBeat
 
Posts: 34
Joined: Tue Jun 26, 2012 11:22 am

Re: How do I set up a project with Xcode4? Been trying for h

Postby ibisum » Tue Jun 26, 2012 11:53 am

First thing I do when I pull a new version of MOAI (I rarely use the SDK release), is open the $MOAI/xcode/ios/ folder, and double-click the XCode project (Moai Sample), then build libmoai, then build and run the sample.

This will package up the iOS package with the sources, and run it on your phone (or simulator?), and so on. If you can get this done, the hard part is over: the MOAI host executable is built, packaged into the iOS app bundle, along with the Lua sources, and off it goes.

Trouble is, this is a build-only configuration: XCode is really crappy for editing the Lua project (navigation/awareness/etc.) and is generally not out-of-the-box ready for using other peoples compiler/build systems, and anyway: you mostly should use XCode only to build, not edit, MOAI projects.

Remember, there is a MOAI host executable, which is what you're really building with XCode, and there is the external MOAI-exclusive Lua-based source tree, which is what XCode is packaging into the bundle to give you the rotating sample.

The XCode project file, as bundled, will refer to a file in the collection called 'moai-target'. This is the *only* file you need to edit, regularly, within XCode - to set it to different values (as you move through the samples, for example), and to set it to your project source directory.

This file should contain the PATH to your MOAI project - everything (and I mean everything, so watch out) that you put in that PATH will be bundled into the iOS App bundle, and then the MOAI executable will be told to run that MOAI project. Thats how it gets bundled up - in fact, XCode is really *only* being used to build the bundle, generally, I think, by most MOAI hackers.

I do all MOAI work in Sublime Text 2 (you could use other editors), and then only use XCode and Android build tools (ant) for device testing and distribution. So, my advice: don't use XCode for *development* of your MOAI app, just use it for building and testing on iOS devices (and eventual building-for-distribution).

Instead, use Sublime Text2 to edit the Lua-based MOAI sources. Get the native MOAI binary for your host (MacOSX moai, Windows moai.exe, Linux moai, etc.) and set up Sublime Text 2 so that, when you hit the Build button, it runs the moai executable with the currently-selected file. Then, open the main.lua, and hit Build -> Have a Running MOAI app on your desktop.

This is a smoother way to develop MOAI apps, once you get it set up.

All that said, there was someone who did get their XCode environment to do pretty much the same thing: run the local host MOAI executable on a selected file; but I have no idea about that and frankly I don't think its as neat to use XCode as it is to use Sublime Text 2, when it comes to editing a Lua-based project.

Try this: open the moai-target file, change the path, switch back to XCode, and hit run. Then directly edit the sample that is pointed to by that path, save the .lua file, hit Run again on XCode. This should work quite smoothly, by the way - but you need to know to edit the Lua project with something else, and also, if you haven't found moai-target by now .. and package.sh .. then you will probably need to read that next.
;
--
ibisum@gmail.com
Got a MOAI snippet? Please consider adding it to http://moaisnippets.info
User avatar
ibisum
 
Posts: 1000
Joined: Mon Oct 17, 2011 1:11 am
Location: Vienna, Austria

Re: How do I set up a project with Xcode4? Been trying for h

Postby SweBeat » Tue Jun 26, 2012 12:40 pm

Thanks, thanks so incredibly much. Now I actually managed to get going. :) Thanks, thanks, thanks.

Now I´m just looking into which editor to use. Sublime looked quite nice, but a little to expensive for me at the moment on my University money I get. But thanks for the tips, and again thanks for the help.
SweBeat
 
Posts: 34
Joined: Tue Jun 26, 2012 11:22 am

Re: How do I set up a project with Xcode4? Been trying for h

Postby rhoster » Tue Jun 26, 2012 4:11 pm

Fantastic post ibisum! Here is an example build system for Sublime Text 2:

Code: Select all
  1. {

  2.         "cmd": ["sh","${project_path}/tools/run.sh"]

  3. }



Then, you open the folder for your project with Sublime and save it as a project. Add a directory to that folder called tools and add the following file called run.sh:

Code: Select all
  1. moai main.lua



If you have your PATH variable set up properly on either Windows, OS X, or Linux, you should be able to get that to work -assuming you have a bash shell installed on Windows. Possible errors are that it can't find the moai executable (meaning your PATH isn't set correctly) or it can't find main.lua (it must not exist in the current directory).

Now you can press Ctrl-B or Cmd-B to run the main.lua file for whatever folder you are in and it should output in the sublime build results display.
User avatar
rhoster
 
Posts: 188
Joined: Sat May 26, 2012 3:59 pm
Location: Santa Barbara, CA


Return to New Users

Who is online

Users browsing this forum: No registered users and 1 guest

x