7

So the "Funscript" page here has a sample. Now I have loaded the sample into my Visual Studio 2012. I am not familiar with Visual Studio .NET and am only learning F# very recently. The last line in the sample pages which is:

do Runtime.Run(components=components, directory="Web") 

always throws an error. In fact the Visual Studio IDE(Compiler) cannot seem to recognize Runtime.

If this was a language like Java, one would try to import a library and so I tried using System.Runtime, but still the Visual Studio IDE does not recognize and the line throws an error saying :

"The namespace or module "Runtime" is not defined.

Two questions

  1. How can I get around this?
  2. Is there any link that teaches F# for the complete beginner that also involves loading external libraries?
Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
N00bsie
  • 469
  • 3
  • 19
  • The tutorial here: http://funscript.info/samples/tutorial.html talks about how to add references to the dlls required. – John Palmer Jul 04 '13 at 23:20
  • I did go through the tutorial and I have added all the dlls. The three dlls mentioned. Any other pointers? In fact I tried looking for references to Runtime and I am unable to find such an error anywhere here in stackoverflow. I do see that the reference is the problem. I tried adding the Funscript references using NuGet as well. I still have the problem. – N00bsie Jul 04 '13 at 23:30
  • Do you have these two lines at the start of your file: `open FunScript` and `open FunScript.TypeScript` – John Palmer Jul 04 '13 at 23:34
  • Of course,I started the sample application only after I read the tutorial! I have looked through all the code samples in the github and I have been unable to reason out why this error occurs! Is there documentation on the 'Runtime' and the 'Interop' modules? – N00bsie Jul 04 '13 at 23:41
  • Well, if you don't post your code, I can only guess at the problem. There is documentation on `System.Runtime` and `System.Runtime.InteropServices` at MSDN, but the `Runtime.Run` is not in these libraries, I believe it is something specific to funscript rather than the F# libs – John Palmer Jul 04 '13 at 23:46
  • This is the code I am using https://github.com/ZachBray/FunScript/blob/master/Examples/Tutorial/Page.fs – N00bsie Jul 04 '13 at 23:52
  • Sorry, we probably don't make this clear enough in the tutorials. This line is actually just a helper for hosting the sample one-page-apps. It isn't actually needed. The core functionality of the library can be used by calling `Compiler.Compile(<@@ @@>, noReturn = true)`. This will return a string containing the JavaScript. – ZachBray Oct 07 '13 at 14:32

1 Answers1

9

I figured this out. Funscript requires a launcher, which is talked about in the documentation. It is contained in Examples/Shared/Launcher.fs. If you use the .fsproj files that come with funscript, this is all handled automatically.

If you are compiling by hand, just add ../Shared/Launcher.fs before you compile your own file.

John Palmer
  • 25,356
  • 3
  • 48
  • 67
  • Thanks so much for your help. How do I actually add ../Shared/Launcher.fs ? I always execute in interactive and I know this isn't the right way. Do I build the solution? – N00bsie Jul 05 '13 at 00:17
  • For fsi, the equivalent is `#load "../Shared/Launcher.fs"` – John Palmer Jul 05 '13 at 00:23
  • I think I did not phrase my question right. I am using a fs file. How do I include another fs file in the same fs file? So I am using Page.fs, Assuming I have a folder with utility functions how do I refer to them? I have tried looking for module loading, but unable to find proper pointers. – N00bsie Jul 05 '13 at 00:37
  • So if you are using `fsc/fsharpc`, you change your command from `fsc A.fs` to `fsc a.fs b.fs`. Otherwise I am confused as to what you are doing to run your code. – John Palmer Jul 05 '13 at 01:02
  • Thanks a lot for your help @John Palmer. I have figured this out and it is working! Thanks so much for your detailed help. – N00bsie Jul 05 '13 at 01:02