3

I am writing an extension for the Scratch text editor application on Elementary OS Luna. But the documentation is practically non-existent for extension creation and I have no idea how to proceed after writing my main code for the extension.

I've already written the extension. I cannot use or test it yet as it needs to be "installed". I spent hours looking for docs but they do not exist. I did however, find a comment on the scratch launchpad page that says

Generally you have to generate a pluginname.so file and put it in lib/scratch/plugins/pluginname with a pluginname.plugin file

Great. This seems like the last part of creating an extension for Scratch. What is a .so file, and how do I generate one? I've already created the other necessary files like the .plugin file and the .vala file.

Yes, I have searched for .so files but all I found were random things about it like using it with C, or C++ headers but obviously that won't work for me, since I'm using Vala?

How do I generate a .so file? What do I generate it from?

uSeRnAmEhAhAhAhAhA
  • 2,527
  • 6
  • 39
  • 64
  • 1
    It's not random! You write the extension in a language that generates a .so file (like C/C++ etc) and then you use it in your scratch app. See this q/a http://stackoverflow.com/questions/9809213/what-are-a-and-so-files – Preet Sangha Nov 28 '13 at 05:21
  • @PreetSangha Thank you for the link :-) Btw, are .so files basically like DLL's in Windows? – uSeRnAmEhAhAhAhAhA Nov 28 '13 at 06:16
  • Do you have any other resources? I have no idea what that page is saying :( – uSeRnAmEhAhAhAhAhA Nov 28 '13 at 06:23
  • yes you're correct. To address you're question. The [link](http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html) in that page shows how they can be created using GCC for example. But you still have to write the code. A question for you would be to enhance your question with some links that have describing what you've followed. Maybe someone can see something that you need to do. – Preet Sangha Nov 28 '13 at 08:14
  • Thank you for helping me, @PreetSangha. I am back now and am looking at your answer. – uSeRnAmEhAhAhAhAhA Nov 28 '13 at 11:46

2 Answers2

2

I think the The Vala tutorial could be helpful on creating the actual Shared library or Shared Object.

You can use the autotools, cmake or you can compile and link a shared library directly from the command line, quoted from the Vala tutorial:

Compilation and linking using Command Line

Vala is not yet capable of directly creating dynamic or static libraries. To create a library, proceed with the -c (compile only) switch and link the object files with your favourite linker, i.e. libtool or ar.

$ valac -c ...(source files) 
$ ar cx ...(object files)

or by compiling the intermediate C code with gcc

$ valac -C ...(source files) 
$ gcc -o my-best-library.so --shared -fPIC ...(compiled C code files)...
Jens Mühlenhoff
  • 14,565
  • 6
  • 56
  • 113
user69969
  • 341
  • 2
  • 10
1

From the Scratch Wiki

Due to browser security restrictions, Scratch 2.0 cannot interact with hardware devices directly. Instead, hardware extensions come with a helper app, a separate application that the user must install and run on their computer. Scratch communicates with the helper app via HTTP requests, and the helper app talks to the hardware. In the future, some extensions may package their helper apps as browser plugins.

Here are the steps for creating and testing a Scratch extension:

  1. Create an extension description file
  2. Create your helper app and start it
  3. Open the Scratch 2 Offline Editor
  4. Import the extension description (shift-click on "File" and select "Import Experimental Extension" from the menu)
  5. The new extension blocks will appear in the More Blocks palette
  6. Test your extension and iterate!

Helper apps can be written in any language that supports server sockets, such as Python, Node.js, Java, C, etc.

Like you I've chased around the wiki but I cannot find an example with source. So all I can do is to address your question generally.

If you look at Build .so file from .c file using gcc command line you'll see how a simple .so can be created. However what code goes into a Scratch extension I don't know. Sorry.

Edit: More googling and I've found a sample from Nathan Dinsmore on GitHub that doesn't use C rather it uses JavaScript, and though it doesn't create a .so extension, it does have what appears to be a full description of creating an extension. He also provides a couple of tutorials.

Edit++ : And here is another sample written in Java.

Community
  • 1
  • 1
Preet Sangha
  • 64,563
  • 18
  • 145
  • 216
  • 1
    I think we are talking about two different things here. The Scratch Wiki you linked to seems to be for something other than the Scratch Text Editor. I think what you linked to is for the Scratch programming language. And the samples you linked to are extensions for the scratch language. I think that's what's so confusing to me; there are no resources for _making extensions **for** the Scratch Text Editor_. – uSeRnAmEhAhAhAhAhA Nov 28 '13 at 11:51
  • There are two Scratch's. There's the Scratch Text Editor that comes with the Linux Distribution Elementary OS and then there's Scratch; a programming language. I am looking for resources for the former. – uSeRnAmEhAhAhAhAhA Nov 28 '13 at 11:53
  • I can not use the information contained within those pages you linked to because to create a Scratch extension (which are written in Vala not C or C++) you do not create executable files, you just save them as .vala files. And that tutorial relies on executable files. I have followed the tutorial but it's not possible to generate a .so file because I have no executable (you don't create executables for Scratch text editor extensions) – uSeRnAmEhAhAhAhAhA Nov 28 '13 at 12:01
  • Ok I see my my mistake, and I suspect I should have waited until you'd put links to the actual 'Scratch' you were referring to. C'est la Vie! Ok should I delete this answer? – Preet Sangha Nov 28 '13 at 12:21