StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
kypaku  
#1 Posted : Saturday, January 16, 2021 8:47:46 AM(UTC)
kypaku

Rank: Member

Reputation:

Groups: Approved
Joined: 11/15/2018(UTC)
Posts: 10
Russian Federation

Thanks: 5 times
Hi! Rob, thank you for your work!

I try to convert all my features from old version and I got a problem:

How can I use 'fs' module for read and write file. I was possible in the old version by using 'io.open' in Lua.
But when I try to use 'fs' - it returns an error 'fs is not defined'. Also the same things happens when I try 'requre'.

Rob  
#2 Posted : Saturday, January 16, 2021 9:40:55 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,382
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 431 time(s) in 364 post(s)
The new version does not use Lua nor support any Lua related functions.

It's now JavaScript, running in Chrome V8 via Microsoft ClearScript. The primary means to perform activities outside of JavaScript is via the Microsoft .NET Framework.

For file operations, you'll want to start with clr.System.IO.File in S+, which resolves to the File class listed below.

https://docs.microsoft.com/en-us/dotnet/api/system.io.file?view=netframework-4.8

If you can provide more specific examples of what you are looking to accomplish, I can give you some more detailed script examples.

Edited by user Saturday, January 16, 2021 9:41:53 AM(UTC)  | Reason: Not specified

thanks 1 user thanked Rob for this useful post.
kypaku on 1/16/2021(UTC)
kypaku  
#3 Posted : Saturday, January 16, 2021 10:10:11 AM(UTC)
kypaku

Rank: Member

Reputation:

Groups: Approved
Joined: 11/15/2018(UTC)
Posts: 10
Russian Federation

Thanks: 5 times
Originally Posted by: Rob Go to Quoted Post

For file operations, you'll want to start with clr.System.IO.File in S+, which resolves to the File class listed below.

Ok, thx.
Well, I try to use it:
Code:

fs = clr.System.IO.File.AppendText('E:/log11.txt')
fs.WriteLine("AAA")

but nothing is happened :( Why?


2) About 'require'
For example I want to use any js library - how can I import it?
kypaku  
#4 Posted : Saturday, January 16, 2021 1:05:53 PM(UTC)
kypaku

Rank: Member

Reputation:

Groups: Approved
Joined: 11/15/2018(UTC)
Posts: 10
Russian Federation

Thanks: 5 times
I did it! About file write :)
The solution:
Code:

const newLine = clr.System.Environment.NewLine;
const writeFile = (path, text) => clr.System.IO.File.WriteAllText(path, text);
const appendFile = (path, text) => clr.System.IO.File.AppendAllText(path, text);
const appendLine = (path, text) => appendFile(path, newLine + text);

Edited by user Saturday, January 16, 2021 1:06:26 PM(UTC)  | Reason: Not specified

Rob  
#5 Posted : Saturday, January 16, 2021 1:23:18 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,382
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 431 time(s) in 364 post(s)
With that method, you need to close the stream for the changes to take effect, I also recommend disposing it as well, though not required.
You can also just append lines with a single statement if that's all you're doing.
Code:
//Just add text to the file (\n for new line)
clr.System.IO.File.AppendAllText('C:\\Temp\\test1.txt', 'BBB\n');

//Open the stream writer
let sw = clr.System.IO.File.AppendText('C:\\Temp\\test1.txt');
sw.WriteLine("AAA");
sw.Close();
sw.Dispose();



require is not a JavaScript keyword, but part of Node.js, so it won't work here.

What kind of libraries are you looking to load? Like, what kind of functionality?

Edited by user Saturday, January 16, 2021 1:34:23 PM(UTC)  | Reason: Not specified

thanks 1 user thanked Rob for this useful post.
kypaku on 1/16/2021(UTC)
Rob  
#6 Posted : Saturday, January 16, 2021 1:29:03 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,382
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 431 time(s) in 364 post(s)
Ha, you posted before I did, and I hadn't refreshed the thread
kypaku  
#7 Posted : Saturday, January 16, 2021 2:04:03 PM(UTC)
kypaku

Rank: Member

Reputation:

Groups: Approved
Joined: 11/15/2018(UTC)
Posts: 10
Russian Federation

Thanks: 5 times
Yes, I see!:)
Well, I just a web-developer and I use some libraries and sometimes build my own. And It would be cool that I can use it in StrokesPlus.
But it seems I found something in 'Examples:
Code:
eval(File.ReadAllText("C:\\Temp\\test.js"));

But it still don't provide require probably...
Rob  
#8 Posted : Saturday, January 16, 2021 2:36:49 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,382
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 431 time(s) in 364 post(s)
You can check out this guy's stuff, it might give you some ideas.

https://www.npmjs.com/package/scripty-strokes?activeTab=readme

thanks 1 user thanked Rob for this useful post.
kypaku on 1/16/2021(UTC)
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.