Posts: 1,031
Threads: 246
Joined: Jul 2022
03-31-2024, 03:15 AM
(This post was last modified: 03-31-2024, 03:16 AM by Davider.)
The code below, when generating the EXE, seems not to package test.cs into the exe(Even within the same folder, it doesn't have any effect).
Is it possible to automatically convert and include this script when generating the exe?
Quote:script.run("test.cs", a1, a2);
Posts: 12,073
Threads: 140
Joined: Dec 2002
script.run("script.cs") means "let LA compile and launch the script". In exe it usually has no sense, and can be replaced with run.it("exe file created from that script"). To automate the "create exe" step can be used /*/ postBuild /*/.
Posts: 1,031
Threads: 246
Joined: Jul 2022
03-31-2024, 05:33 AM
(This post was last modified: 03-31-2024, 05:35 AM by Davider.)
Thanks for your reminder. It would be best if there's a corresponding prompt in the output pane when generating the EXE, provided the command exists.
How's the execution speed(script.run)? Does it recompile every time?
Posts: 12,073
Threads: 140
Joined: Dec 2002
LA recompiles before run only if something changed (code, used files, environment...).
Posts: 1,031
Threads: 246
Joined: Jul 2022
03-31-2024, 06:04 AM
(This post was last modified: 03-31-2024, 06:05 AM by Davider.)
In LA, how can we implement asynchronous execution of a specific script within a single EXE? similar to the following QM code(single EXE)
Macro AA
mac "M1" "" "hello"
mes "world"
Function M1
Posts: 12,073
Threads: 140
Joined: Dec 2002
03-31-2024, 06:31 AM
(This post was last modified: 03-31-2024, 06:32 AM by Gintaras.)
Move exe2 code to exe1, and run that code in separate thread.
run.thread(() => {
//code
//moved
//from
//exe2
});
Posts: 1,031
Threads: 246
Joined: Jul 2022
03-31-2024, 06:49 AM
(This post was last modified: 03-31-2024, 07:27 AM by Davider.)
In actual work, I may have multiple script codes that need to be asynchronously executed under specific conditions.
It is not very convenient to manage if all the scripts are placed in a single file...
I have an idea, when generating the EXE:
Quote:script.run("exe2.cs", a1, a2);
Automatically converted to( generate temporary code before compiling):
run.thread(() => {
//code
//moved
//from
//exe2
});
Posts: 12,073
Threads: 140
Joined: Dec 2002
Script codes don't have to be in single file. Let the script files be in the same project folder as the main script, as class files. Modify script codes to not have top-level statements or Main function, because only the main script can/must have it.
Posts: 12,073
Threads: 140
Joined: Dec 2002
03-31-2024, 07:32 AM
(This post was last modified: 03-31-2024, 07:49 AM by Gintaras.)
Example.
Files in folder @Example100. Note: folder name starts with @.
// script "Example100.cs"
var b = new wpfBuilder("Window").WinSize(400);
b.R.AddButton("Start TaskA", _ => { run.thread(TaskA.Thread); });
b.R.AddButton("Start TaskB", _ => { run.thread(() => TaskB.Thread(5)); });
b.R.AddOkCancel();
b.End();
if (!b.ShowDialog()) return;
// class "TaskA.cs"
static class TaskA {
public static void Thread() {
dialog.show(null, "TaskA");
}
}
// class "TaskB.cs"
static class TaskB {
public static void Thread(int x) {
dialog.show(null, $"TaskB, x={x}");
}
}
Posts: 1,031
Threads: 246
Joined: Jul 2022
03-31-2024, 08:28 AM
(This post was last modified: 03-31-2024, 08:48 AM by Davider.)
thank you!
Create new file always generates it at the top of the files list, which is somewhat inconvenient.
Suggestion: It's recommended that new files are generated in the same directory as the currently open file.
https://i.ibb.co/WDnBtDK/AAA.png
Posts: 1,031
Threads: 246
Joined: Jul 2022
03-31-2024, 12:06 PM
(This post was last modified: 03-31-2024, 12:08 PM by Davider.)
I find it inconvenient to add parameters for debugging in the classFile role, whereas scripting in the miniProgram role is much more convenient.
I have an idea: add a button to the toolbar to switch between the two roles, making it easier to debug functions in the class
For example:
Clicking the button for the first time sets the script role to miniProgram, resulting in the following code:
/*/ role miniProgram; /*/
static class TaskB
{
static void Main()
{
Thread(5);
}
public static void Thread(int x)
{
dialog.show(null, $"TaskB, x={x}");
}
}
_______________________________________________________________________________________________________
Clicking the button for the second time sets the script role to classFile, resulting in the following code:
static class TaskB
{
static void _Main()
{
Thread(5);
}
public static void Thread(int x)
{
dialog.show(null, $"TaskB, x={x}");
}
}
Posts: 12,073
Threads: 140
Joined: Dec 2002
Use code like in the last chapter of https://www.libreautomate.com/editor/Cla...jects.html
Then the class file must be not in a project.
// class "ClassHH.cs"
/*/ role miniProgram; define TEST; /*/
#if TEST
TaskB.Thread(5);
#endif
static class TaskB
{
public static void Thread(int x)
{
dialog.show(null, $"TaskB, x={x}");
}
}
In script Example100.cs add /*/ c ClassHH.cs; /*/
Posts: 1,031
Threads: 246
Joined: Jul 2022
Thanks for your help. I just understood the article above until now.
Posts: 12,073
Threads: 140
Joined: Dec 2002
Another way.
Use code like in #9, but let the main script call TestScript.RunFile (which can be anywhere, eg in a class file added with /*/ c /*/).
// script "Example100.cs"
if (script.testing && TestScript.RunFile(("TaskA", TaskA.Thread), ("TaskB", () => TaskB.Thread(5)))) return;
var b = new wpfBuilder("Window").WinSize(400);
b.R.AddButton("Start TaskA", _ => { run.thread(TaskA.Thread); });
b.R.AddButton("Start TaskB", _ => { run.thread(() => TaskB.Thread(5)); });
b.R.AddOkCancel();
b.End();
if (!b.ShowDialog()) return;
static class TestScript {
/// <summary>
/// If a specified file is currently active in editor, executes <b>Action</b> and returns true.
/// </summary>
/// <param name="files">List of tuples <c>(string file, Action action)</c>, where <b>file</b> is the filename (without ".cs") of a class file from current project, and <b>action</b> is a callback function to call if that file is the active file in editor.</param>
public static bool RunFile(params (string file, Action action)[] files) {
var w = ScriptEditor.MainWindow();
var f = w.Elm["DOCUMENT", "document - *", "class=Scintilla"];
f.ResultGetProperty = 'n';
if (f.Exists()) {
var s = (f.ResultProperty as string)[11..];
foreach (var (n, a) in files) {
if (n.Eqi(s)) {
a();
return true;
}
}
}
return false;
}
}
Posts: 1,031
Threads: 246
Joined: Jul 2022
03-31-2024, 11:57 PM
(This post was last modified: 04-01-2024, 12:10 AM by Davider.)
about #12
Could you add an option in the output panel's prompt text that, when clicked, automatically adds the code within the purple rectangle? also, add See More , This would be beginner-friendly for programming novices.
https://i.ibb.co/5YpKjx8/AA.png
often encounter the following error message.
at line 4 in ClassHH.cs, Program.<Main>$(String[] args)
Posts: 1,031
Threads: 246
Joined: Jul 2022
Error message: Permission denied to delete file, but I am executing as an administrator.
Quote:System.UnauthorizedAccessException: Access to the path 'C:\Users\Administrator\Desktop\240401_144335.dat' is denied.
at line 11 in ClassHH.cs, TaskB.Thread(Int32 x)
at line 4 in ClassHH.cs, Program.<Main>$(String[] args)
>>
https://i.ibb.co/0q5qWkG/AA.png
Posts: 12,073
Threads: 140
Joined: Dec 2002
Next LA will print example code when converted role.
Also added ScriptEditor.TestCurrentFileInProject; use like TestScript.RunFile in #14.
Exception - unrelated.
Posts: 1,031
Threads: 246
Joined: Jul 2022
In the new version of LA, do we still need all the code from #14? It would be great if we could hide the implementation details.
|