Friday, May 20, 2016

Get Command Line Lua Working On Mac And Windows

Having used Lua for a long time now, I realised that I've never actually run it as a stand-alone feature. So I figured I would find out how to run it from the command line. There are two routes to take and I stumbled a few times, until realising that it's way simpler than it can appear. I guess it depends on your mindset as to how you interpret some of the steps.

Note: This post was written when Lua 5.3.2 was the current version, but as none of the steps (or formal references) here have changed since v1, I don't see that it would be a different process for any other version.

I should point out here that I have been using Lua during my use of Corona SDK by CoronaLabs and it is so easy and just a great language. It is a lot older than it might appear, having been created around 1991. Check the bottom of this post for all the references.

So, here's how to get it working step by step...

Command Line Lua on Mac from the Binary:
  • Download the latest version for "Mac OS X Intel Executables" from:
  • This will get you a .tar file with a name like "lua-5.3.2_MacOS1011_bin.tar" (relevant to the version you downloaded) in your download location.
  • Decompress the .tar file and you will have a directory with the same name, minus the ".tar", something like "lua-5.3.2_MacOS1011_bin"
    • At this point you have downloaded the Lua binary and have everything you need to run Lua code.
  • Open Terminal by either going to Launchpad, Spotlight or Applications->Utilities->Terminal
    • This is the command line program for Mac and lets you execute instructions on the Mac directly. It is similar to CMD.exe on Windows, but uses a Unix instruction set. (You don't need to worry about this.)
  • If you have downloaded the Lua binary to Downloads in your own user folder you need to navigate to that. Steps:
    • The full path for your own user directory will be something like: /users/mattw and the terminal is probably already there.
    • Type: pwd to find out where you are. You should see something like /users/mattw
    • If you are in your user directory you can see what is in it by typing (this is not necessary): ls
    • To go into the Downloads folder type: cd Downloads
      • Tip: To autocomplete any file or folder name you can type part of it and then hit Tab
    • If you type ls again you will probably see a lot more - everything which is in your Downloads folder.
    • Type: cd lua-5.3.2_MacOS1011_bin to go into the decompressed Lua binary folder (you might want to type cd lua and press Tab here)
    • Type ls again to see what is inside the folder for your version of Lua.
    • You should now see two files. They will be called "lua" and "luac" plus the shortened version number of Lua which you have downloaded.
      • Eg: "lua53" and "luac53"
  • Note: From here we will check that the Lua binary is working on the command then. You can skip ahead to run a lua program, if you have one.
  • Check that you can run Lua on the Terminal command line by typing: ./lua53 (The . and / are important!)
    • You should see this (with the appropriate version and date):
      • Lua 5.3.2  Copyright (C) 1994-2015, PUC-Rio
    • Type:
      • > print("Hello World!")
    • You should see this:
      • > print("Hello World!")
        Hello World!
    • You have successfully installed Lua and executed your first line of Lua code!
    • One thing to note is that you are currently in the Lua command line - not the Terminal command line any more.
    • To get back to regular Terminal, type CTRL+C
    • From here you can run Lua programs which are saved in ".lua" files.
  • To run a Lua program create a new text file in a text editor (e.g. TextEdit) and save it in the same folder as the Lua binary - inside the decompressed Lua folder - and make sure it ends with ".lua" (all Lua programs must end in .lua)
    • Create a file in a text editor.
    • In the text file, copy and paste this:
math.randomseed( os.time() )
print( "%c" ) )
print( os.time() )
for i=1, 10 do
print("Counter: "..i)
    • Save the file inside the decompressed Lua folder and name it: main.lua
    • To run the program, go back to Terminal and type:
      • ./lua53 main.lua
      • Again, the "./" at the start is important and the "53" is for the version I am using. Yours may be different.
    • You should now see something similar to this:
Sat May 21 07:14:31 20161463811271Counter: 1Counter: 2Counter: 3Counter: 4Counter: 5Counter: 6Counter: 7Counter: 8Counter: 9Counter: 1048
    • As you can probably see in the program file, this is the current date, an integer representing the current date, a loop from 1 to 10 and a random number.
    • I'm not going to explain the Lua language here - there are plenty of references for that (see below) but you can start here:
    • The Corona Labs site also has a very good documentation system, but it is heavily geared towards their libraries - Corona is a very good starting point to learn Lua:
Command Line Lua on Mac from the Source:

Before we get started, I do need to point out that you will need XCode by Apple installed to be able to compile the Lua source into a binary. This is not a problem as it is available from the Mac App Store and Apple Developer website, but if you do install it and don't run it first you will likely see a message about the license (this would happen when XCode gets updated, as well.) When this happens, simply run XCode and accept the update terms. You can quit it immediately, as it is not necessary to have it running to build the Lua source code.
  • TBC
Command Line Lua on Windows from the Binary:
  • TBC
Command Line Lua on Windows from the Source:
  • TBC

Monday, April 11, 2016

TextWrangler Document Drawer Next And Previous Navigation

If you are using Bare Bones' "little brother to BBEdit" app TextWrangler (also available on the Mac App Store) you might want to use the file drawer (CMD+0 to open on the left in version 5.0.2). It allows you to use one window to edit multiple files.

There is a really handy keyboard shortcut to switch between those files, making navigating between all your documents quick and easy:
  • CMD+Alt+[ for previous document and CMD+Alt+] for next document
The default setting, however, is to navigate from previous to next document in the order they have been opened. If you manually select a document with the mouse, the order is then switched to the order as opened, or loaded. This can be incredibly annoying as you really have no idea which document will be the 'next' document!

You can search all day long for a Preferences setting but you will not find it. It is not there.

Googling for answers on this can also be frustrating, though I have done the leg work for you and can reveal that the Mac's Terminal is to your rescue...
  • Simply type Terminal into Spotlight (CMD+space) and hit return 
  • Type: 
  • defaults write com.barebones.textwrangler SurfNextPreviousInDisplayOrder -bool YES 
  • Hit return and close Terminal
You should now find that TextWrangler navigates through your files in the order they are listed in the document drawer.


Monday, March 14, 2016

Understand Large Code Bases

Having been assigned a series of very large code bases over the past few months, I decided to do some digging on how different developers choose to understand them, in general. Being able to digest other people's code is important and the challenge increases hugely very quickly when you're working in an enterprise environment.

While there is a lot of advice on how to do a great many things in software, much of it requires understanding all the tools around you and the business logic involved - often to a very deep level. The problem here is that you may not be familiar with those tools and the business logic probably is not written down, let alone digestible.

Coping with these issues is often, glibly, described as getting experience with the tools and just reading the code as much as possible. This is not helpful. Firstly, it does not advise on how to approach a large system - where best to begin reading and what to do when what you're reading doesn't make sense - and how to cope with the deluge of information found when looking up toolsets being used on a large, often legacy, project.

I fully intend to expand on this post at some point with truly useful information, but for now I will link to some helpful, though not oracle-like, posts found around the internets. These probably state the obvious techniques you've already tried - I know I have. They also might incite you to keep going, as maintaining will power can be a challenge, too.

Friday, February 27, 2015

Innovation is Saying No to 1000 Things

Having just read this over at Daring Fireball I was reminded of this video shown by Apple at WWDC in 2013:


It made me think about the oft-debated and ongoing argument about why some companies produce as many varied products and Apple doesn't, while Apple is roundly criticised at every turn for not including every feature under the sun while still making 90% of the market's profit.

Companies like Samsung see value in producing as many variations of a product to appeal to as many customers as possible. The failure in that strategy is that it requires the majority of those variations to not be attractive to most customers. The reason that strategy can be put into action at all is because those numerous variations can be produced at low cost, which itself incurs a penalty of low quality.

Wednesday, February 25, 2015

Force VMWare Fusion Windows 7.1 on Retina Mac to Reasonable Resolution

Running Windows 7.1 under VM Ware Fusion on a Retina MacBook Pro will cause each restart (whether shutdown or put into sleep mode) to start back up in the highest resolution available. Windows does not cater for this the same way that Mac OS does and the upshot is that everything on your screen will be tiny.

To force Windows into a reasonable resolution the VMWare VMX config file for the instance needs to be modified to set the max width and height. Finding the config file is the first step. Adding three lines is the second.

The long way is to follow the instructions on these two pages in order:
The short version of those is to shutdown your VM Windows (not suspend) and open the following menu:
  • Window -> Virtual Machine Library ->
  • Then, while holding alt / option, open the menu over the Windows instance in the left menu
  • "Show in Finder" will change to "Open Config in File Editor"
Then, in your text editor, paste these three lines to the bottom of the config file and save it over the original (make a backup):
svga.autodetect = "FALSE"
svga.maxWidth = 1920
svga.maxHeight = 1200
This will set the default resolution to 1920x1200. Choose whichever is best for you.

Thursday, January 29, 2015

Sample Code

Bunch of sample codes I've written for use in lua on the Corona SDK, utility and math libraries.
Some of these may appear in both lists due to being a library within a demo.

I have now added a third list of other people's libraries as they are proving quite useful.



Sample/Demo code:


Wednesday, October 29, 2014

Payment Security

There has been a lot of talk in the tech and regular media recently about digital security so I just wanted to write a word about some of these issues by passing on some links to read.

Firstly, a note about mobile payments in shops:

The gist here is that many shops are doing whatever they can to deter people from using Apple Pay over other solutions because Apple Pay stops the shops and related merchants from accessing personal information about the people shopping with them.

If you’re wondering why this would be a bad thing, here is an article about the type of information that shops are trying to collect about every single person who walks through their doors:

If you didn’t read that (TL; DR), it says that what Target (huge chain in America) is trying to do is work out if you’re pregnant even if you don’t want them to know from your spending habits.

Yes, this stuff is possible. And we are at the start of an enormous digital path. Many people thought that contactless payments would not catch on because of the insecurity – if you have a mobile register you can walk past someone’s pocket and charge them up to £20 without them knowing (this has happened) – however we now have contactless everywhere because of the convenience.

We have actually been on this path for a while – contactless was introduced back in 1997. Consumers have been wanting a “pay by phone” method for a long time (I even pay for parking using an iPhone app) simply for the convenience.

What we have gained in convenience we have lost in security. Be careful out there. Choose what you pay with and who you pay with care.

Further reading: