The following is a guide on how to download and configure IntelliJ IDEA for use with MOAI/LUA development. It is based heavily on information found in this thread, although it goes into a great deal more detail and uses the most recent versions as of 8/22/2012.
First and foremost, go and download IntelliJ IDEA from this link. Assuming you don’t want to spend money, use the Community Edition version. I have the full version of WebStorm and sadly, it isn’t fully compatible with the following steps. Once your download completes, run the installer.
Once installed, run IntelliJ. Select the menu File->Settings:
On the left hand side, scroll down and locate Plugins, and highlight it:
On the right hand side, locate and click Browse repositories…
In the resulting dialog, in the top right search box enter Lua. Then locate Lua in the results and double click:
A confirmation dialog should pop up, choose ‘Yes’
In the status bar at the bottom of the window, a download progress bar will appear, wait for it to complete. Now click OK on the Browse repositories dialog to close it, then Apply in the Settings window. You will be prompted:
Choose Restart. Let IntelliJ restart.
Now head over to this thread and download the attached file moai_sdk.zip. ( Or use this direct link ). Save that archive and extract it’s contents somewhere (permanent ). In my case I used C:APIsmoai-sdkIntelliJ which is a sub-directory I created under my MOAI install folder, the actual location doesn’t really matter.
Now in IntelliJ IDEA, create a new Lua project. Select File->New Project… Check ‘Create project from scratch’, then click Next:
In the bottom left under ‘Select Type’ select Lua Module, then fill in a project name and location. Click Next:
Kahlua should display as Lau SDK version, click the Finish and your project will be created.
Now on the left hand side in the Project panel, expand External Libraries and right click Kahlua and select ‘Open Library Settings’ ( or hit F4 )
In the resulting Window, under the Classpath tab, click the small ‘+’ icon.
Now navigate to the directory you extracted the archive to earlier and select the directory then click OK. It should update like this:
Click Apply, then OK to close the Settings window.
You are now setup to do LUA/MOAI development in IntelliJ, but… IT DOESN’T WORK UNTIL YOU RESTART. Alright, done yelling, just figured that point was important. For some reason, intellisense wont start working until you restart IntelliJ, so do that now.
Now create a new LUA script. Right click your project in the Project panel, select New->Lua Script:
Call it main.lua and click OK:
Now if you start typing, autocomplete will work:
And Presto! Don’t worry, all of that work takes perhaps two or three minutes, it just looks like a ton of work because of the level of detail I went into. Now onto…
Configuring IntelliJ IDEA to run you Moai game
Ok, so this part is completely optional, but will make it easier for you to run a game directly from IntelliJ. We are going to create a pair of External Tools. Again, it will look harder than it is.
In IntelliJ, select File->Settings:
On the left hand side, scroll down and locate External Tools and select it:
On the right hand side, locate the + icon and click it:
In the Edit Tool dialog, name it Run Moai, in the group Moai, set the Program: value to point to where you’re MOAI host is, in my case c:Apismoai-sdkbinwin32moai.exe for parameters set it to $FileName$, which is a macro for the current selected files name; then set Working Directory to $FileDir$, which will expand to the current files directory. Now click OK.
Click Apply and OK on the External Tools window to close it.
Now you need some code to run. If you don’t have any code to enter in Main.lau, use the following bare bones application for testing purposes.
MOAISim.openWindow ( "test", 320, 480 ) viewport = MOAIViewport.new () viewport:setSize ( 320, 480 ) viewport:setScale ( 320, -480 ) viewport:setOffset ( -1, 1 ) layer = MOAILayer2D.new () layer:setViewport ( viewport ) MOAISim.pushRenderPass ( layer )
Once you’ve added that code to main.lau, save it, then in the menu select Tools->Moai->Run Moai like so:
If the menu isn’t there, something went wrong with the prior setup, make sure that you clicked Apply after editing. After you select Run Moai, your application should appear:
After it runs, you will see the results of the console window in IntelliJ’s Run panel, like so:
If it doesn’t, and you have an error like the following:
Make sure that you have your .lua file selected before you choose Run Moai. Simply click it in the editing window before running.
This setup does however present a bit of a problem… MOAI logs errors out to the standard console while it is running, but IntelliJ will only display the console once running is complete. This obviously isn’t ideal if you are trying to debug your application or if non-terminal errors are occurring, but don’t worry, there is an easy fix.
Configuring IntelliJ to run Moai in a separate console/terminal window
See, sometimes we want to launch a terminal window that launches our Moai host. This process is remarkably similar with a minor tweak.
Once again, select File->Settings. Scroll down and select External Tools, on the right hand side select Moai then click the + icon. In the Edit Tool dialog, fill it out as follows:
Name it ‘Run Moai with Command Prompt’, select the Group Moai.
Under program enter cmd.exe
Under Parameters, enter ( obviously adjusting to your Moai install directory ): /c START C:APIsmoai-sdkbinwin32moai.exe $FileDir$$FileName$
Under working directory, enter: $FileDir$
Then click OK to close the Edit tool window, then Apply then OK to close the Settings window.
Now click inside moai.lua to focus it, then choose the menu Tools->Moai->Run Moai with Command Prompt:
Moai running, with a command prompt receiving output. I added a print statement to the sample code to generate a bit of output.
There you go, a fully configured IDE for creating and running Moai applications in IntelliJ IDEA with auto complete. The only downside is, the text completion is not smart enough to figure out dynamic values. For example, it cannot handle : completions like this:
viewport = MOAIViewport.new () viewport:setSize ( 320, 480 )
It will offer auto completion on the first line, but has no idea the members in the second, so if you type viewport: you will get no recommendations. If you know a way to fix this, please let me know!
Hope that guide proved useful.