Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$runtime is not defined #12

Closed
ghost opened this issue Jun 11, 2011 · 7 comments
Closed

$runtime is not defined #12

ghost opened this issue Jun 11, 2011 · 7 comments

Comments

@ghost
Copy link

ghost commented Jun 11, 2011

Opal example works fine for me but if I try precompile ruby code (browser.rb) I get this error:
$runtime is not defined (in precompiled browrser.rb, I called browser.js)

I use HTML code like this:

<script src="../../extras/opal.js"></script>
<script src="../../extras/opal.dev.js"></script>    
<script type="text/javascript" src="browser.js"></script>

I've tried removing opal.dev.js, I've tried rquery.js (from homepage) but I always get the same error.

Any help? Thank you in advance.

@adambeynon
Copy link
Contributor

Hey. How are you compiling the code (ruby tools? altjs.org?)? Also, can you paste the code that it is generating?

@ghost
Copy link
Author

ghost commented Jun 11, 2011

I compile browser.rb with this command:
opal compile browser.rb > browser.js

I've updated my browser.js file: https://gist.github.com/1020856

Of course, I use opal edge version (git clone).

Thank you again. Great piece of work!

@ghost ghost closed this as completed Jun 11, 2011
@ghost ghost reopened this Jun 11, 2011
@ghost
Copy link
Author

ghost commented Jun 11, 2011

Ooooops! I closed this issue by mistake!

@adambeynon
Copy link
Contributor

Ahhhhh, it seems that the compile command misses out a little piece of code. Basically that outputted code should be inside a function which defines the $runtime variable. I'll go fix that and update you here once its all working again.

@adambeynon
Copy link
Contributor

So I've just committed a fix for this at 102a979. You need to pull the latest changes, regenerate opal.js or opal.dev.js (either will do) and recompile your file with that same command you used before. The generated code is now properly wrapped and will be run directly. Let me know if this solves the issue.

@ghost
Copy link
Author

ghost commented Jun 11, 2011

Great!
Now it works OK.

Opal rocks! Thank you!

@ghost ghost closed this as completed Jun 11, 2011
@adambeynon
Copy link
Contributor

Glad Its working. Just as a follow up, I've just pushed b1f5a1f to master which adds some more build options to the compile command. In your use case, it has the same effect except that the generated code will now be written directly to the output file which it assumes from your input filename, so the following should work for you:

bin/opal compile browser.rb

Which outputs the code to browser.js.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant