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

Commit 5fc96f7

Browse files
committed
MLC: Add "the operating system" syntax.
The new syntax resolves to one of the following strings: * "windows" -- 32-bit and 64-bit Windows * "mac" -- Desktop OS X * "ios" -- iOS (iPhone and iPad) * "android" -- Android Linux devices * "linux" -- All other Linux platforms
1 parent 1365291 commit 5fc96f7

File tree

6 files changed

+116
-0
lines changed

6 files changed

+116
-0
lines changed

libscript/Makefile.libscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ SOURCES += \
2222
module-sort.cpp \
2323
module-stream.cpp \
2424
module-string.cpp \
25+
module-system.cpp \
2526
module-type_convert.cpp \
2627
module-type.cpp \
2728
module-url.cpp \

libscript/libstdscript-modules.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ math.mlc
1414
sort.mlc
1515
stream.mlc
1616
string.mlc
17+
system.mlc
1718
type.mlc
1819
type-convert.mlc

libscript/src/module-system.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* -*-c++-*-
2+
Copyright (C) 2015 Runtime Revolution 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+
#include <foundation.h>
19+
20+
/* ================================================================
21+
* System identification
22+
* ================================================================ */
23+
24+
extern "C" MC_DLLEXPORT void
25+
MCSystemExecGetOperatingSystem (MCStringRef & r_string)
26+
{
27+
const char t_os[] =
28+
#if defined(__IOS__)
29+
"ios"
30+
#elif defined(__MAC__)
31+
"mac"
32+
#elif defined(__WINDOWS__)
33+
"windows"
34+
#elif defined(__ANDROID__)
35+
"android"
36+
#elif defined(__LINUX__)
37+
"linux"
38+
#else
39+
# error "Unrecognized operating system"
40+
#endif
41+
;
42+
43+
/* UNCHECKED */ MCStringCreateWithCString (t_os, r_string);
44+
}

libscript/src/system.mlc

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright (C) 2015 Runtime Revolution 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+
/*
19+
This library provides low-level system functionality for modular
20+
LiveCode programs.
21+
*/
22+
23+
module com.livecode.system
24+
25+
----------------------------------------------------------------
26+
-- Platform identification
27+
----------------------------------------------------------------
28+
29+
public foreign handler MCSystemExecGetOperatingSystem(out Platform as string) as undefined binds to "<builtin>"
30+
31+
/*
32+
Summary: The operating system
33+
34+
Example:
35+
if the operating system is "linux" then
36+
- Platform specific-code
37+
end if
38+
39+
Description:
40+
Returns a string describing the operating system that LiveCode is
41+
running on. The possible values are:
42+
43+
* "windows" - 32-bit and 64-bit Windows
44+
* "mac" - Desktop OS X
45+
* "ios" - iOS (iPhone and iPad)
46+
* "android" - Android Linux devices
47+
* "linux" - All other Linux platforms
48+
49+
Tags: System
50+
*/
51+
syntax OperatingSystem is expression
52+
"the" "operating" "system"
53+
begin
54+
MCSystemExecGetOperatingSystem(output)
55+
end syntax
56+
57+
--
58+
59+
end module

toolchain/lc-compile/src/module-helper.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ extern builtin_module_descriptor __com_livecode_segmentchunk_module_info;
4242
extern builtin_module_descriptor __com_livecode_sort_module_info;
4343
extern builtin_module_descriptor __com_livecode_stream_module_info;
4444
extern builtin_module_descriptor __com_livecode_string_module_info;
45+
extern builtin_module_descriptor __com_livecode_system_module_info;
4546
extern builtin_module_descriptor __com_livecode_type_module_info;
4647
extern builtin_module_descriptor __com_livecode_typeconvert_module_info;
4748

@@ -65,6 +66,7 @@ builtin_module_descriptor* g_builtin_modules[] =
6566
&__com_livecode_sort_module_info,
6667
&__com_livecode_stream_module_info,
6768
&__com_livecode_string_module_info,
69+
&__com_livecode_system_module_info,
6870
&__com_livecode_type_module_info,
6971
&__com_livecode_typeconvert_module_info
7072
};
@@ -85,6 +87,7 @@ extern void (*MCMathFoundationExecRoundRealToNearest)();
8587
extern void (*MCSortExecSortListAscendingText)();
8688
extern void (*MCStreamExecWriteToStream)();
8789
extern void (*MCStringEvalConcatenate)();
90+
extern void (*MCSystemExecGetOperatingSystem)();
8891
extern void (*MCTypeEvalIsEmpty)();
8992
extern void (*MCTypeConvertExecSplitStringByDelimiter)();
9093

@@ -105,6 +108,7 @@ void *g_builtin_ptrs[] =
105108
&MCSortExecSortListAscendingText,
106109
&MCStreamExecWriteToStream,
107110
&MCStringEvalConcatenate,
111+
&MCSystemExecGetOperatingSystem,
108112
&MCTypeEvalIsEmpty,
109113
&MCTypeConvertExecSplitStringByDelimiter
110114
};

toolchain/lc-compile/test.mlc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module test
33
use com.livecode.math
44
use com.livecode.file
55
use com.livecode.stream
6+
use com.livecode.system
67

78
public handler test()
89
variable tResults as list
@@ -68,6 +69,9 @@ public handler test()
6869

6970
--com.livecode.stream
7071
testStream(tResults)
72+
73+
--com.livecode.system
74+
testSystem(tResults)
7175

7276
--com.livecode.binary
7377
--com.livecode.byte
@@ -923,5 +927,8 @@ public handler testStream(inout xResults as list)
923927

924928
end handler
925929

930+
public handler testSystem(inout xResults as list)
931+
testLog("System", "OperatingSystemNonEmpty", the operating system is not empty, xResults)
932+
end handler
926933

927934
end module

0 commit comments

Comments
 (0)