Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 38b024f

Browse files
committed
[[ Bug 20705 ]] Add 'the architecture' syntax to LCB
1 parent 8278e71 commit 38b024f

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

docs/lcb/notes/20705.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# LiveCode Builder Standard Library
2+
3+
## System module
4+
5+
# [20705] Add 'the architecture' syntax

libscript/src/module-system.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ MCSystemExecGetOperatingSystem (MCStringRef & r_string)
4646
/* UNCHECKED */ MCStringCreateWithCString (t_os, r_string);
4747
}
4848

49+
extern "C" MC_DLLEXPORT_DEF void
50+
MCSystemExecGetArchitecture(MCStringRef & r_string)
51+
{
52+
const char t_arch[] =
53+
#if defined(__X86__) || defined(__i386__)
54+
"x86"
55+
#elif defined(__X86_64__)
56+
"x86_64"
57+
#elif defined(__ARM64__)
58+
"arm64"
59+
#elif defined(__ARM__)
60+
"arm"
61+
#elif defined(__EMSCRIPTEN__)
62+
"js"
63+
#else
64+
# error "Unrecognized architecture"
65+
#endif
66+
;
67+
68+
/* UNCHECKED */ MCStringCreateWithCString (t_arch, r_string);
69+
}
70+
4971
/* ================================================================
5072
* Command-line information
5173
* ================================================================ */

libscript/src/system.lcb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,34 @@ begin
5656
MCSystemExecGetOperatingSystem(output)
5757
end syntax
5858

59+
public foreign handler MCSystemExecGetArchitecture(out Architecture as String) returns nothing binds to "<builtin>"
60+
/**
61+
Summary: The architecture
62+
63+
Example:
64+
if the architecture is "x86_64" then
65+
-- Do something x86_64 specific
66+
end if
67+
68+
Description:
69+
Returns a string describing the instruction set architecture
70+
that is being used by the machine LiveCode is running on.
71+
The possible values are:
72+
73+
* "x86" - 32-bit x86 builds
74+
* "x86_64" - 64-bit x86 builds
75+
* "arm" - 32-bit arm builds
76+
* "arm64" - 64-bit arm builds
77+
* "js" - Emscripten
78+
79+
Tags: System
80+
*/
81+
syntax Architecture is expression
82+
"the" "architecture"
83+
begin
84+
MCSystemExecGetArchitecture(output)
85+
end syntax
86+
5987
----------------------------------------------------------------
6088
-- Exit / Quit
6189
----------------------------------------------------------------

tests/lcb/stdlib/system.lcb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright (C) 2017 LiveCode Ltd.
3+
4+
This file is part of LiveCode.
5+
6+
LiveCode is free software; you can redistribute it and/or modify it under
7+
the terms of the GNU General Public License v3 as published by the Free
8+
Software Foundation.
9+
10+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
11+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
17+
18+
module com.livecode.system.tests
19+
20+
use com.livecode.system
21+
use com.livecode.__INTERNAL._testlib
22+
23+
constant kValidArchs is ["x86", "x86_64", "arm", "arm64", "js"]
24+
public handler TestArchitecture()
25+
test "architecture is valid" when \
26+
the architecture is in kValidArchs
27+
end handler
28+
29+
end module

0 commit comments

Comments
 (0)