Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| libraries:machine_code [2023-12-17 02:15] – [Tools/libraries] Update library links geek | libraries:machine_code [2024-03-07 13:46] (current) – Remove subheader to improve embedded page appearance geek | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Machine Code ====== | ====== Machine Code ====== | ||
| - | Machine Code (referred to as " | + | Machine Code (referred to as " |
| - | + | ||
| - | MCode is especially useful for performance critical operations like physics calculation or image processing, since compiled C code is much faster than the compiled C++ code which is used to interpret regular AHK code. | + | |
| - | + | ||
| - | However, due to the unique constraints of code being executed inside of AHK by '' | + | |
| - | + | ||
| - | ===== Tools/ | + | |
| * [[https:// | * [[https:// | ||
| * [[libraries: | * [[libraries: | ||
| - | ==== MCL ==== | ||
| - | |||
| - | <tabbox AutoHotkey v1> | ||
| - | <runner ahk1> | ||
| - | #Requires AutoHotkey v1.1 | ||
| - | |||
| - | #Include <MCL> | ||
| - | |||
| - | c = | ||
| - | ( | ||
| - | #define UNICODE | ||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | // Export a global variable | ||
| - | MCL_EXPORT_GLOBAL(someGlobal); | ||
| - | int someGlobal = 42; | ||
| - | |||
| - | // Export a function | ||
| - | MCL_EXPORT(someFunction) | ||
| - | int someFunction(AHK_OBJECT *obj) { | ||
| - | AHK_FIELD* field; | ||
| - | LPTSTR key = L" | ||
| - | if (!AhkObjGetStr(obj, | ||
| - | return 0; | ||
| - | return AhkFieldAsInt(field) * someGlobal; | ||
| - | } | ||
| - | ) | ||
| - | lib := MCL.FromC(c) | ||
| - | |||
| - | MsgBox % " | ||
| - | NumPut(2, lib.someGlobal, | ||
| - | MsgBox % " | ||
| - | |||
| - | obj := {" | ||
| - | MsgBox % "obj is:" | ||
| - | Print(obj) | ||
| - | MsgBox % " | ||
| - | |||
| - | ; Compile the code into an includeable function | ||
| - | ; MsgBox % MCL.StandaloneAHKFromC(c) | ||
| - | </ | ||
| - | <tabbox AutoHotkey v2> | ||
| - | <runner ahk2> | ||
| - | #Requires AutoHotkey v2.0 | ||
| - | |||
| - | #Include <MCL> | ||
| - | |||
| - | c := " | ||
| - | ( | ||
| - | #include < | ||
| - | |||
| - | // Export a global variable | ||
| - | MCL_EXPORT_GLOBAL(someGlobal, | ||
| - | int someGlobal = 42; | ||
| - | |||
| - | // Export a function | ||
| - | MCL_EXPORT(someFunction, | ||
| - | int someFunction(int* outputVarName) { | ||
| - | // Multiply the inout parameter by the global | ||
| - | *outputVarName *= someGlobal; | ||
| - | return 1; | ||
| - | } | ||
| - | )" | ||
| - | lib := MCL.FromC(c) | ||
| - | |||
| - | MsgBox " | ||
| - | lib.someGlobal := 2 | ||
| - | MsgBox " | ||
| - | |||
| - | out := 123 | ||
| - | MsgBox "out was " out | ||
| - | MsgBox " | ||
| - | MsgBox "out is " out | ||
| - | |||
| - | ; Compile the code into an includeable class | ||
| - | ; MsgBox MCL.StandaloneAHKFromC(c) | ||
| - | </ | ||
| - | </ | ||
| - | |||
| - | |||