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

[m8n] NLua8

Installation

Experiences detailed here has been run after installing

Loading S8 in NLua console application

We want load the S8 kernel snapshot to test if it runs, as it should be.
The S8 kernel snapshot can be found in m8n folder as s8.snapshot.lua

Building the console application

  1. Create an application called NLuaConsole as a project dependent on NLua/NLua
  2. Edit the Program.cs file to be:
    using System;
    using NLua;
    
    namespace NLuaConsole
    {
        class Program
        {	
            static void Main(string[] args)
            {
                var state = new Lua();
                string folder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                state.DoFile( folder + "\\s8.snapshot.lua" );
    
                var result = state.DoString("return smalltalk.Object:selectors():sorted():asLiteral()", "lua expression")[0];
                Console.WriteLine("(lua) Object selectors = " + result);
    
                result = state.DoString("local code=[[ " +
                    "self print: '(s8) Senders of #yourself'. " +
                    "#yourself senders do: [:each| self print: '  ',each ]" +
                    " ]]; return code:fileIn()", "s8 expression")[0];
            }
        }
    }


loading s8.snapshot.lua

  1. Copy the snapshot file (s8.snapshot.lua) to the folder where the target executable exists. In case of using Visual Studio 2019, in debug mode, the generated executable will be "NLuaConsole\bin\Debug\netcoreapp2.2\NLuaConsole.dll"
  2. Run the application e.g. in Visual Studio enter debugger to run the application

Conclusions

If all is ok you will see, in the console windows, the result of evaluating two expressions:
  1. accessing smalltalk.Object to send #selectors message and get result as a string (after sorting, etc)
  2. evaluating a chunk of code via fileIn, where printing (#print:) is routed from S8 to console window

S8 is running fine and we expect that it will run OK in this environment.
It is more work to be done to feel comfortable working in this platform, but from this point ALL can be done on S8 side, using wrappers and transparent/native access; the same way we work on other platforms.

U8 Tools, Libraries and Wrappers for .Net


References

  1. NLua web page
  2. NLua Github repo
  3. .Net Resources

Notes

Output of NLuaConsole application using the default s8.snapshot.lua
C:\C\lua\dotNet\NLuaConsole>dotnet NLuaConsole.dll
(lua) Object selectors = #( -> = == #__tostring #accept: #actionForEvent: #actionListForEvent: #addDependent: #argumentCount #asActionSequence #asJS #asJSON #asJSONObject #asJavascript #asJson: #asLiteral #asLua #asNative #asNative: #asNativeHandle #asParser #asString #basicAt: #basicAt:ifAbsent: #basicAt:ifAbsentPut: #basicAt:put: #basicDelete: #basicInspect #basicPerform:withArguments: #canTriggerEvent: #cancelFileIn #changed #changed: #changed:with: #changed:with:with: #class #copy #deepCopy #deepCopyOf: #dependents #dnu:withArguments: #doesNotUnderstand: #emmit: #emmit:startingWith: #error: #escapedCode #evaluate #evaluateDeferred #evaluateWith: #evaluateWithArguments: #eventTable #eventTableCreate #eventTableForEdit #eventsHandled #fileIn: #fileInJS: #halt #handleOf: #hasActionForEvent: #ifNil: #ifNil:ifNotNil: #ifNotNil: #ifNotNil:ifNil: #ifUndefined: #ignoreFileInUpTo: #implementedBySubclass #implementedBySubclass: #initialize #inspect #instVarAt: #instVarAt:put: #invalidEvent: #invalidMessage #invalidMessage: #isArray #isAssociation #isBoolean #isCharacter #isClass #isDictionary #isFile:olderThan: #isKindOf: #isMemberOf: #isMessage #isMetaclass #isNil #isNumber #isObject: #isParseFailure #isRectangle #isString #javascriptCodeFollows #json #jsonExportNil #jsonFieldsDo:ignoring: #jsonHiddenNames #logEvaluate: #methodFor: #mustBeBoolean #mustBeNumber #nativeLanguage #notImplementedYet #notImplementedYet: #notNil #note: #numberOfArguments #orNil #perform: #perform:with: #perform:withArguments: #print: #printString #printingWith:do: #release #releaseEventTable #removeAction:forEvent: #removeActionsForEvent: #removeActionsSatisfying:forEvent: #removeActionsWithReceiver:forEvent: #removeAllActionsWithReceiver: #respondsTo: #scanFrom: #setActionList:forEvent: #shallowCopy #shouldNotImplement #shouldNotImplement: #size #smalltalk #smalltalkErrorOf: #subclassResponsibility #subclassResponsibility: #toString #triggerEvent: #triggerEvent:ifNotHandled: #triggerEvent:with: #triggerEvent:with:ifNotHandled: #triggerEvent:with:with: #triggerEvent:withArguments: #triggerEvent:withArguments:ifNotHandled: #typeOf: #update: #update:with: #updateEvent:selector:arguments: #when:do: #when:evaluate: #when:send:to: #when:send:to:withArguments: #yourself ~= ~~ )
(s8) Senders of #yourself
  Object>>#smalltalkErrorOf:
  Snapshot>>#saveImage:on:
  Collection>>#,
  Collection>>#fileOut
  Collection>>#export
  Collection>>#copyWithAll:
  Collection>>#copyWith:
  Collection class>>#withAll:
  Collection class>>#with:with:with:with:
  Collection class>>#with:with:with:
  Collection class>>#with:with:
  Collection class>>#with:
  Array class>>#with:with:
  Array class>>#with:with:with:
  Array class>>#with:with:with:with:
  Array class>>#with:
  ComposedAssociations>>#,
  PoolDictionary class>>#@@
  NativeObject class>>#buildLuaStaticFunctions:
  NativeObject class>>#buildLuaFunctions:
  ChunkReader class>>#doing:until:
  Behavior>>#buildPool:with:
  Behavior>>#implement:comment:as:category:
  Behavior>>#allImplementedMessages
  Behavior>>#allMessagesSent
  Behavior>>#collection
  Exporter>>#exportAllCategories
  Exporter>>#exportCategories:
  Exporter>>#fileOutCategories:
  Exporter class>>#allClasses
  CompiledMethod>>#references
  PPInlineParser class>>#upTo:
  PPListParser class>>#withAll:
  PPDelegateParser class>>#on:
  PPActionParser class>>#on:block:
  PPRepeatingParser class>>#on:min:
  Stream class>>#on:
  ReturnNode class>>#variable:at:
  SequenceNode>>#asBlockSequenceNode
  SendNode>>#cascadeNodeWithMessages:
  SendNode>>#valueForReceiver:
  JSDirectiveNode class>>#code:protected:
  Message class>>#receiver:selector:arguments:
  Message class>>#selector:arguments:
  ActionSequence class>>#withAll:
  Compiler>>#nodeFromTemplateIn:
  Compiler class>>#debugInfo:forClass:
  Compiler class>>#for:
  MethodReferences>>#referencesOfClassVariable:
  MethodReferences>>#sendersOf:
  MethodReferences>>#globalReferencesOf:
  SmalltalkParser>>#optDirective:ws:
  SmalltalkParser>>#methodParserParts
  SmalltalkParser>>#parser
  OptimizingEncoder>>#optimizationLiteralsFor:
  LuaEncoder>>#defaultKnownOptimizations