Rank: Member
Groups: Approved
Joined: 11/15/2018(UTC) Posts: 10 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'.
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,382 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.8If 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
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Member
Groups: Approved
Joined: 11/15/2018(UTC) Posts: 10 Thanks: 5 times
|
Originally Posted by: Rob 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?
|
|
|
|
Rank: Member
Groups: Approved
Joined: 11/15/2018(UTC) Posts: 10 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
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,382 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
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,382 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
|
|
|
|
Rank: Member
Groups: Approved
Joined: 11/15/2018(UTC) Posts: 10 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...
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,382 Location: Tampa, FL Thanks: 28 times Was thanked: 431 time(s) in 364 post(s)
|
|
1 user thanked Rob for this useful post.
|
|
|
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.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close