Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Automatically convert and include scripts when generating the exe
#1
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);
#2
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 /*/.
#3
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?
#4
LA recompiles before run only if something changed (code, used files, environment...).
#5
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
 
Code:
Copy      Help
mac "M1" "" "hello"
mes "world"

Function M1
Code:
Copy      Help
function ~s1
mes s1
#6
Move exe2 code to exe1, and run that code in separate thread.
 
Code:
Copy      Help
run.thread(() => {
    //code
    //moved
    //from
    //exe2

});
#7
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):
 
Code:
Copy      Help
run.thread(() => {
    //code
    //moved
    //from
    //exe2
});
#8
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.
#9
Example.
Files in folder @Example100. Note: folder name starts with @.
 
Code:
Copy      Help
// 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;
 
Code:
Copy      Help
// class "TaskA.cs"
static class TaskA {
    public static void Thread() {
        dialog.show(null, "TaskA");
    }
}

Code:
Copy      Help
// class "TaskB.cs"
static class TaskB {
    public static void Thread(int x) {
        dialog.show(null, $"TaskB, x={x}");
    }
}
#10
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
#11
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}");
    }
}
#12
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.

Code:
Copy      Help
// 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; /*/
#13
Thanks for your help. I just understood the article above until now.
#14
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 /*/).
Code:
Copy      Help
// 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;
    }
}
#15
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)
#16
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
#17
Next LA will print example code when converted role.
Also added ScriptEditor.TestCurrentFileInProject; use like TestScript.RunFile in #14.
 


Exception - unrelated.
#18
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.


Forum Jump:


Users browsing this thread: 3 Guest(s)