Monkey: basic app structure

 

Strict

Import mojo

Function Main:Int()
  New MyGame()
  Return 0
End Function

Class MyGame Extends App

  'Called once, do your initialization here!
  Method OnCreate:Int()
    SetUpdateRate(30)
    Return 0
  End Method

  'Called 30 times per second (normally)
  Method OnUpdate:Int()
    Return 0
  End Method

  'This is called when the user pressed the home button!
  Method OnSuspend:Int()
    Return 0
  End Method

  'This is called when the user switches back to your app and it's still alive!
  Method OnResume:Int()
    Return 0
  End Method

  'This is called when something is rendered to the screen
  Method OnRender:Int()
    Cls()
    DrawText( "Hello there", 10, 10 )
    Return 0
  End Method

  'This is called when the back button was pressed!
  Method OnBack:Int()
    'Ok, just exit the app for test purposes!
    EndApp()
    Return 0
  End Method
End Class

Objective-C: resizing an UIImage

-(UIImage*)imageWithImage:(UIImage*)image 
                 scaledToSize:(CGSize)newSize;
{
 UIGraphicsBeginImageContext( newSize );
 [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
 UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();

 return newImage;
}

 

// grab the original image
UIImage *originalImage = [UIImage imageNamed:@"myImage.png"];
// scaling set to 2.0 makes the image 1/2 the size. 
UIImage *scaledImage = [UIImage imageWithCGImage:[originalImage CGImage] scale:2.0 orientation:UIImageOrientationUp];

 

Test AppleScript

--example 1
set theFile to (choose file with prompt "Select a file to read:" of type {"TEXT"})
open for access theFile
set fileContents to (read theFile)
close access theFile

--example 2
on readFile( unixPath )
  set foo to (open for access (POSIX file unixPath ))
  set txt to (read foo for (get eof foo))
  close access foo
  return txt
end readFile

--example 3 UTF-16
on readFile( unixPath )
  set foo to (open for access (POSIX file unixPath ))
  set txt to (read foo for (get eof foo) as Unicode text)
  close access foo
  return txt
end readFile

--example 4 UTF-8
on readFile( unixPath )
  set foo to (open for access (POSIX file unixPath ))
  set txt to (read foo for (get eof foo) as «class utf8»)
  close access foo
  return txt
end readFile

--example 5 with terminal
on readFile( unixPath )
  return (do shell script "cat '" & unixPath & "'")
end