none
Building an extension... With SB? RRS feed

  • Question

  • A while back on this forum I read that it is possible to build an extension with Small Basic. How would this be done?
    Tuesday, March 9, 2010 8:12 PM

Answers

  • You can do this an any .Net language (VB, C# or C++, frankly all very similar) using the Express 2008 (or beta 2010) (both free) version of MS development studio.

    There is the original blog outlining how to do this in C#:

    http://blogs.msdn.com/smallbasic/archive/2008/10/27/extending-small-basic.aspx

    Also, there is source code in various of the above flavours (Fremy's extension and some others - start at the Small Basic Wiki for links to most).

    http://wiki.smallbasic.com/smallbasic.com/wiki/Downloads.ashx
    Tuesday, March 9, 2010 9:28 PM
    Moderator
  • Sounds like a reference to Fremy's Small Basic Extension Compiler

    Forum Link
    http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/1a3f54f3-8412-40ff-a06b-08dc65a49530


    Sky Drive Link
    http://cid-201f3835d49587fe.skydrive.live.com/self.aspx/Public/Small%20Basic/SmallBasicExtensionCompiler.zip

    Yes you can use Small Basic to create a DLL file used by Small Basic, but it hasn't been updated.  It only works with version 0.6 of the SmallBasicLibrary.dll

    Basically you create and save a .sb file and run through Fremy's SmallBasicExtensionCompiler.exe.  This creates a .dll to be put into Small Basic's lib folder.  The filename appears as an object, Subs become operations.

    Wednesday, March 10, 2010 3:47 AM
  • As an example, I'll post a one-line calculator I modified to work in Small Basic.  The original code is from Jack Crenshaw's "Let's Build A Compiler"

    Edit: corrected decimal point error

    http://smallbasic.com/smallbasic.com/program/?JGV972-0
    note: this published version calls Calc() at the end of the file, the .dll does not.

    Calculator.dll for use with v0.8
    http://cid-ac79d3543f73aa54.skydrive.live.com/browse.aspx/MyPublicFiles


    To use the .dll, copy the file to your Small Basic\lib folder.
    Start Small Basic and a Calculator object will appear in the Intellisense Wheel

    The only operation(or sub) visible is Calc.  Everything else is hidden by use of the underscore character _ .

    here's a sample of its use-
    menu:
    'TextWindow.Clear()
    TextWindow.WriteLine("")
    TextWindow.WriteLine("")
    TextWindow.WriteLine("Please choose an option (1-?)")
    TextWindow.WriteLine("")
    TextWindow.WriteLine(" 1. ")
    TextWindow.WriteLine(" 2. ")
    TextWindow.WriteLine(" 3. ")
    TextWindow.WriteLine(" 4. One Line Calculator")
    TextWindow.WriteLine("")
    TextWindow.WriteLine(" 9. Clear the TextWindow")
    TextWindow.WriteLine(" 0. Quit")

    TextWindow.WriteLine("")
    TextWindow.Write("> ")
    menuSelection = TextWindow.ReadNumber()
    TextWindow.WriteLine("")
    If (menuSelection = 1) Then
    ElseIf (menuSelection = 2) Then
    ElseIf (menuSelection = 3) Then
    ElseIf (menuSelection = 4) Then
      Calculator.Calc()
    ElseIf (menuSelection = 9) Then
      TextWindow.Clear()
    ElseIf (menuSelection = 0 Or menuSelection = "") Then
      Program.End() 
    EndIf

    Goto menu

    Select option 4, then enter an expression like you would in Small Basic
    ex. 4*5+(7+13)
    and the expression will be parsed and an answer spit out on the screen.
    Wednesday, March 10, 2010 7:18 AM
  • Sorry, I didn't update my program because I've lost his source code during the change of computer (I had decompiled the Small Basic executables in the C:\Program Files\Microsoft Small Basic\ and modified it accordoingly, and this directory gets deleted when I moved from XP to Seven).

    But I can remeber the code was pretty simple : in fact, I just decompiled SmallBasicCompiler.exe, deleted few lines (for example, the line added at the end of the Main() method that was outputting "Press ENTER to continue" or something like that.

    Additionnaly, the Program was named using the filename (and not using _SmallBasicProgram as in the real compiler), put some attibutes so that the visible properties and methods could be visible for Small Basic (additionnaly, I set the Main() method as a static constructor for the class, so that the code in the Main() would run immediately before the extension become used). I also think I needed to change the fields type to property, so that they could be seen by Small Basic (though I'm unsure).

    It could be done very quickly to redo this work (the most complex part is the decompiling of the Small Basic fils and the tuning up of the code so that it compiles again), but as I'm out of time currently, so I don't think I'll perform it before a rather long time.

    As an alternative workaround, you could write your application using Small Basic, upgrade it to to VB.NET and add the needed stuff of code to allow this to be recognized as an extension by Small Basic (in fact, adding some <Attribute's()> could be sufficient). I think it's what Rushworks did (Am I right here ?)

    To respond to those who asked how to make your own "Controls.Add****" methods, I would say it's nearly impossible for a beginner, since you'll need to use and understand many concepts like Reflection, use of private functions of Small Basic, use WPF Classes and handle thread-safe delegates for WPF-modifications. I'm ready to publish the source code (I think an old version of my API is published opensourcely somewhere) but there's very few chance you could modify it for doing something new.
    Fremy - Developer in VB.NET, C# and JScript ... - Feel free to try my extension
    Wednesday, March 17, 2010 11:21 AM

All replies

  • You can do this an any .Net language (VB, C# or C++, frankly all very similar) using the Express 2008 (or beta 2010) (both free) version of MS development studio.

    There is the original blog outlining how to do this in C#:

    http://blogs.msdn.com/smallbasic/archive/2008/10/27/extending-small-basic.aspx

    Also, there is source code in various of the above flavours (Fremy's extension and some others - start at the Small Basic Wiki for links to most).

    http://wiki.smallbasic.com/smallbasic.com/wiki/Downloads.ashx
    Tuesday, March 9, 2010 9:28 PM
    Moderator
  • Sounds like a reference to Fremy's Small Basic Extension Compiler

    Forum Link
    http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/1a3f54f3-8412-40ff-a06b-08dc65a49530


    Sky Drive Link
    http://cid-201f3835d49587fe.skydrive.live.com/self.aspx/Public/Small%20Basic/SmallBasicExtensionCompiler.zip

    Yes you can use Small Basic to create a DLL file used by Small Basic, but it hasn't been updated.  It only works with version 0.6 of the SmallBasicLibrary.dll

    Basically you create and save a .sb file and run through Fremy's SmallBasicExtensionCompiler.exe.  This creates a .dll to be put into Small Basic's lib folder.  The filename appears as an object, Subs become operations.

    Wednesday, March 10, 2010 3:47 AM
  • So Fremy hasn't updated that? And can you give an example of SmallBasic code to make an object and operations?
    Wednesday, March 10, 2010 5:04 AM
  • As an example, I'll post a one-line calculator I modified to work in Small Basic.  The original code is from Jack Crenshaw's "Let's Build A Compiler"

    Edit: corrected decimal point error

    http://smallbasic.com/smallbasic.com/program/?JGV972-0
    note: this published version calls Calc() at the end of the file, the .dll does not.

    Calculator.dll for use with v0.8
    http://cid-ac79d3543f73aa54.skydrive.live.com/browse.aspx/MyPublicFiles


    To use the .dll, copy the file to your Small Basic\lib folder.
    Start Small Basic and a Calculator object will appear in the Intellisense Wheel

    The only operation(or sub) visible is Calc.  Everything else is hidden by use of the underscore character _ .

    here's a sample of its use-
    menu:
    'TextWindow.Clear()
    TextWindow.WriteLine("")
    TextWindow.WriteLine("")
    TextWindow.WriteLine("Please choose an option (1-?)")
    TextWindow.WriteLine("")
    TextWindow.WriteLine(" 1. ")
    TextWindow.WriteLine(" 2. ")
    TextWindow.WriteLine(" 3. ")
    TextWindow.WriteLine(" 4. One Line Calculator")
    TextWindow.WriteLine("")
    TextWindow.WriteLine(" 9. Clear the TextWindow")
    TextWindow.WriteLine(" 0. Quit")

    TextWindow.WriteLine("")
    TextWindow.Write("> ")
    menuSelection = TextWindow.ReadNumber()
    TextWindow.WriteLine("")
    If (menuSelection = 1) Then
    ElseIf (menuSelection = 2) Then
    ElseIf (menuSelection = 3) Then
    ElseIf (menuSelection = 4) Then
      Calculator.Calc()
    ElseIf (menuSelection = 9) Then
      TextWindow.Clear()
    ElseIf (menuSelection = 0 Or menuSelection = "") Then
      Program.End() 
    EndIf

    Goto menu

    Select option 4, then enter an expression like you would in Small Basic
    ex. 4*5+(7+13)
    and the expression will be parsed and an answer spit out on the screen.
    Wednesday, March 10, 2010 7:18 AM
  • How would you make something like fremy's, Controls.AddRectangle(.............)?
    Wednesday, March 10, 2010 10:26 PM
  • Impressive, Rushworks.  I love this expression evaluator!

    Thursday, March 11, 2010 4:40 PM
    Moderator
  • Vijaye, When Will "Introducing Small Basic.pdf" Be Updated.
    Signature: Phillip Mikesell
    Monday, March 15, 2010 12:41 AM
  • I would be interested in writing it.
    Monday, March 15, 2010 4:29 AM
  • I would be interested in writing it.
    VJ already knows every feature in sb, so id rather he'd write it. if you do make one send it to phillipqwert@live.com
    Signature: Phillip Mikesell
    Monday, March 15, 2010 6:24 PM
  • There is no desputing that VJ is the Authority.  I just thought that they may be wanting to expand the team.  I believe that this is going to be a very important product and I would like to be part of it.
    Monday, March 15, 2010 7:02 PM
  • Robert,

    Good quality written documentation, worked examples, sample projects with step-by-step guides etc is something SmallBasic is lacking.  It is also good to create this from a range of perspectives (the code developer may well be best to do an API, but a good guide with examples teaching the features is a different skill).

    If you are interested in this I think it will be appreciated by a large number of potential users.
    Monday, March 15, 2010 7:10 PM
    Moderator
  • I would be interested!
    Monday, March 15, 2010 9:02 PM
  • As a side note you may consider adding content to the Small Basic wiki.

    http://smallbasic.com/smallbasic.com/wiki/MainPage.ashx

    Monday, March 15, 2010 9:06 PM
  • I love the enthusiasm of this Forum!

    There are some legal issues with Microsoft shipping documents created by volunteers (the same issues we ran into while trying to enlist volunteer help for localization).  It would be super-helpful if you all can beef-up our Wiki (http://smallbasic.com/wiki) - since it shows up on web searches, more people can benefit from that.

    Monday, March 15, 2010 9:36 PM
    Moderator
  • Robert,

    As far as I know, there is no official team doing this job.  I would certainly encourage you making a start.

    When you have something started and got some basic ideas together you should ask for help from the community.

    Perhaps you can then generate a list of ideas that remain to be explained.  Some of us can create small examples to demonstrate these with explanations of the point being described and how the code achieves it, what it does and why it was done this way, pitfalls etc (i.e useful help).

    The wiki is a good place to add examples, but ultimately something more structured and comprehensive in scope would be great - I suspect if a good start is made people will chip in and help (I certainly will), especially if someone has done the hard work of thinking what is required and coordinate/collate a bit.
    Monday, March 15, 2010 10:06 PM
    Moderator
  • Sorry, I didn't update my program because I've lost his source code during the change of computer (I had decompiled the Small Basic executables in the C:\Program Files\Microsoft Small Basic\ and modified it accordoingly, and this directory gets deleted when I moved from XP to Seven).

    But I can remeber the code was pretty simple : in fact, I just decompiled SmallBasicCompiler.exe, deleted few lines (for example, the line added at the end of the Main() method that was outputting "Press ENTER to continue" or something like that.

    Additionnaly, the Program was named using the filename (and not using _SmallBasicProgram as in the real compiler), put some attibutes so that the visible properties and methods could be visible for Small Basic (additionnaly, I set the Main() method as a static constructor for the class, so that the code in the Main() would run immediately before the extension become used). I also think I needed to change the fields type to property, so that they could be seen by Small Basic (though I'm unsure).

    It could be done very quickly to redo this work (the most complex part is the decompiling of the Small Basic fils and the tuning up of the code so that it compiles again), but as I'm out of time currently, so I don't think I'll perform it before a rather long time.

    As an alternative workaround, you could write your application using Small Basic, upgrade it to to VB.NET and add the needed stuff of code to allow this to be recognized as an extension by Small Basic (in fact, adding some <Attribute's()> could be sufficient). I think it's what Rushworks did (Am I right here ?)

    To respond to those who asked how to make your own "Controls.Add****" methods, I would say it's nearly impossible for a beginner, since you'll need to use and understand many concepts like Reflection, use of private functions of Small Basic, use WPF Classes and handle thread-safe delegates for WPF-modifications. I'm ready to publish the source code (I think an old version of my API is published opensourcely somewhere) but there's very few chance you could modify it for doing something new.
    Fremy - Developer in VB.NET, C# and JScript ... - Feel free to try my extension
    Wednesday, March 17, 2010 11:21 AM
  • BTW, nothing linked to extension' building but will you publish a Small Basic compilator for Windows Phone 7 Series. If you can make SB' apps working on Silverlight on the web, it would be possible to launch them on WP7S, right ?
    Fremy - Developer in VB.NET, C# and JScript ... - Feel free to try my extension
    Wednesday, March 17, 2010 11:23 AM