• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Run Javascript code on Desktop

Sammi3

Member
Hello,

I wanted to make an extension of a third party API for one of my projects. The API comes in numerous languages but the ones I'm most comfortable using are C++ and Javascript. I would rather use javascript for an extension as the extension would be a file that's cross platform rather than creating the relevant dll, dylib files for mac and windows. Would it be possible to run javascript code on a Desktop target through an extension? I'm leaning on a no as there would be no way to execute it but perhaps there's a workaround?

Thanks in advance.

EDIT: I meant C++ not C# :p
 
Last edited:

FrostyCat

Redemption Seeker
You could if you manage to stick V8 into an extension, but that's just extra native-level work for little added value.
 

Evanski

Raccoon Lord
Forum Staff
Moderator
Hello,

I wanted to make an extension of a third party API for one of my projects. The API comes in numerous languages but the ones I'm most comfortable using are C# and Javascript. I would rather use javascript for an extension as the extension would be a file that's cross platform rather than creating the relevant dll, dylib files for mac and windows. Would it be possible to run javascript code on a Desktop target through an extension? I'm leaning on a no as there would be no way to execute it but perhaps there's a workaround?

Thanks in advance.
https://marketplace.yoyogames.com/assets/575/execute-shell

@Samuel Venable
 

Pfap

Member
You could if you manage to stick V8 into an extension, but that's just extra native-level work for little added value.
This crossed my mind too, but I think the extra value would come with being able to build extensions for any platform with javascript. With extensions it seems a lot of the extra native work becomes needing a different language per platform to get functionality not included with Gamemaker; objective c for ios, java for android, javascript for html5, and of course c++. I don't have any experience building extensions, but have edited already made ones for advertising. It would be a much less daunting task to build an extension if you could choose one language for all exports.
 
S

Sam (Deleted User)

Guest
I wrote another extension not mentioned here that not only executes and evaluates JavaScript strings but also does so without executing any external applications, and is done all within your game's application process. (Unless of course the JavaScript itself you specify runs an external program). I removed it from the Marketplace because no one reviewed it or gave feedback on it in my topic for it there was. It could also run VBScript. Doing a Mac port shouldn't be too hard, maybe after I've done that, and an AppleScript interpreter, I can publish it again for you guys and report back to you. Sound good?
 

Sammi3

Member
Yes that would be really great :) So with this extension, you pass the javascript code as a string? and it parses and executes it?
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Using Node.JS for this might be an overkill, both because a packed binary is ~5MB and because that's actually not enough JavaScript to actually port any library originally targeting browsers (which obviously have additional APIs).

I have at one point attempted to write a duktape wrapper, but had to back out of that idea after discovering that, due to implementation specifics, it would not be possible to let JS code call any GML scripts at anyhow reasonable speed.

This crossed my mind too, but I think the extra value would come with being able to build extensions for any platform with javascript. With extensions it seems a lot of the extra native work becomes needing a different language per platform to get functionality not included with Gamemaker; objective c for ios, java for android, javascript for html5, and of course c++. I don't have any experience building extensions, but have edited already made ones for advertising. It would be a much less daunting task to build an extension if you could choose one language for all exports.
For the most part, you can write all extensions in C++, but for iOS/Android you will have to use some ObjC/Swift/Java for the simple reason that calling platform's functions otherwise might be more trouble than you are prepared for.

I wrote another extension not mentioned here that not only executes and evaluates JavaScript strings but also does so without executing any external applications, and is done all within your game's application process. (Unless of course the JavaScript itself you specify runs an external program). I removed it from the Marketplace because no one reviewed it or gave feedback on it in my topic for it there was. It could also run VBScript. Doing a Mac port shouldn't be too hard, maybe after I've done that, and an AppleScript interpreter, I can publish it again for you guys and report back to you. Sound good?
If that was with JScript, that may not have matching APIs - it's purpose is shell scripting, after all.
 
S

Sam (Deleted User)

Guest
Using Node.JS for this might be an overkill, both because a packed binary is ~5MB and because that's actually not enough JavaScript to actually port any library originally targeting browsers (which obviously have additional APIs).

I have at one point attempted to write a duktape wrapper, but had to back out of that idea after discovering that, due to implementation specifics, it would not be possible to let JS code call any GML scripts at anyhow reasonable speed.


For the most part, you can write all extensions in C++, but for iOS/Android you will have to use some ObjC/Swift/Java for the simple reason that calling platform's functions otherwise might be more trouble than you are prepared for.


If that was with JScript, that may not have matching APIs - it's purpose is shell scripting, after all.
Yeah I wasn't sure if he meant JavaScript or JScript in terms of Windows. But Mac can do straight up JavaScript last I checked.

Yes that would be really great :) So with this extension, you pass the javascript code as a string? and it parses and executes it?
Is JScript ok for what you are wanting on Windows? JScript is basically Microsoft's own version of JavaScript, but it isn't capable of doing all of the same things. It can run native code through the help of ActiveX however.

If nothing else I can at least get Mac doing JavaScript for you. I hope that is any help.
 

Sammi3

Member
Yeah I wasn't sure if he meant JavaScript or JScript in terms of Windows. But Mac can do straight up JavaScript last I checked.



Is JScript ok for what you are wanting on Windows? JScript is basically Microsoft's own version of JavaScript, but it isn't capable of doing all of the same things. It can run native code through the help of ActiveX however.

If nothing else I can at least get Mac doing JavaScript for you. I hope that is any help.
To be honest, I'm not quite sure of the differences between JScript and Javascript as I thought they were the same thing. I wouldn't be using any node. Just accessing resources on the internet.
 
Top