[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

Console Mode walkthrough


Console mode is the basic mode of operation and development of S8. It can be used to develop frameworks and applications for multiple platforms; using a file based schema (boot the system from javascript and smalltalk files) or image based (boot + precompiled files or complete snapshot). For a more detailed information you can see de console index page.
In this walkthrough you will see minimal aspects of console development trying to construct a typical hello world sample. You can find a more development oriented sample in Word counter tutorial

  1. Download the console contribution for your platform: Win 32 bits, Win 64 bits, Mac OSX, Linux
  2. Unziping the contribution file you should see the following:
    Uploaded Image: console1.png
    You can see s8vm.exe & s8x64.exe the two s8 virtual machines for 32 & 64 bit (this sample was done in Windows platform). Typically building a S8 project implies using s8vm.exe so you must operate with console commands to launch the compilation. You could have a build.bat file invoking s8vm.exe (or s8x64.exe) with a main director script (a javascript file) as argument.
    NOTE: Take care if you move s8vm.exe/s8x64.exe to other folders, please check Moving s8vm.exe to other location

  3. Create a build.bat file:
    Code
    File: build.bat
    s8vm.exe --shell build.js
  4. Create a main director script build.js file:
    Code
    File: build.js
    (function() {
       try	{
            print("// S8 - Console bootstrap.");
    	load("s8/boot.js");
    	load("s8/s8.image.js"); //load minimal S8 image
    	load("s8/initialize.js");
    	load("s8/initialize.st.js"); 
    	emmit("helloWorldSampleApp.st"); 
            //fileIn('build.st');        //fileIn source code (chunk format)
            //fileInJS('fileName.st.js');	// load compiled code (javascript)
    	smalltalk.Snapshot.outputToFile_("helloWorld.snapshot.js");
    	print('=====Build OK=====');
    	quit();	
    	}
       catch (err) {
    	print('====Error===='+err);
    	print(err.stack);
    	quit();
        }	
    })();
    
    First part of script loads S8 minimal image plus several related functionalities. This is a console sample application so s8.image.js is required, if you need to build a web application with UI8 + WI8 frameworks for application support and GUI widgets you should use ui8.image.js. More info about this in [web] Application startup
    The emmit statement compiles smalltalk chunk format code, in this case our hello world sample.
    The next two commented lines, shows you can file in code in building process (this aspect it will covered in next step). Last statement defines where all compiled source code will be integrated into a snapshot.
  5. Change main director script build.js file to:
    Code
    File: build.js
    (function() {
       try	{
            print("// S8 - Console bootstrap.");
    	load("s8/boot.js");
    	load("s8/s8.image.js"); //load minimal S8 image
    	load("s8/initialize.js");
    	load("s8/initialize.st.js"); 
    	//emmit("helloWorldSampleApp.st"); 
            fileIn('build.st');        //fileIn source code (chunk format)
            //fileInJS('fileName.st.js');	// load compiled code (javascript)
    	smalltalk.Snapshot.outputToFile_("helloWorld.snapshot.js");
    	print('=====Build OK=====');
    	quit();	
    	}
       catch (err) {
    	print('====Error===='+err);
    	print(err.stack);
    	quit();
        }	
    })();
    
    You can control what is going to be emmited wihtout doing this in javascript context. Let's create the build.st file and define what is emmited:
    Code
    File: build.st
    self emmit:'helloWorldSampleApp.st'!
    
  6. Create helloWorldSampleApp.st file:
    Code
    File: helloWorldSampleApp.st
    Object
       subclass: #HelloWorld
       instanceVariableNames: ''
       category: #TestConsole !
    
    ! HelloWorld class methodsFor: #launching !
    launch
    	" Private - Launch. "
    	self print: 'Hello world from console'! !
    
    At this point you should have four new files:
    Uploaded Image: console3.png
  7. Just go to console and build the project:
    Uploaded Image: console4.png
  8. At this point you shhould see a generated helloWorld.snapshot.js.
    Create run.bat file:
    Code
    File: run.bat
    s8vm.exe --expose-gc --shell helloWorld.snapshot.js
    
    Then executing
    Uploaded Image: console5.png
    you have done your first console development. Congratulations!