Skip to content

Commit 93f302e

Browse files
committed
[[ Log ]] Implement the logMessage global property
1 parent 04be442 commit 93f302e

File tree

9 files changed

+78
-0
lines changed

9 files changed

+78
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Name: logMessage
2+
3+
Type: property
4+
5+
Syntax: set the logMessage to <handlerName>
6+
7+
Summary:
8+
The name of the handler that is called by the <log> command.
9+
10+
Introduced: 9.5
11+
12+
OS: mac, windows, linux, ios, android, html5
13+
14+
Platforms: desktop, server, mobile
15+
16+
Example:
17+
on preOpenStack
18+
-- uBuildMode property set before building standalone
19+
if the uBuildMode of this stack is "release" then
20+
set the logMessage to empty
21+
end if
22+
23+
loadResources
24+
end preOpenStack
25+
26+
command loadResources
27+
log "loading resources"
28+
end loadResources
29+
30+
on log pInfo
31+
-- unhandled put will go to system logs
32+
put pInfo
33+
end log
34+
35+
Value:
36+
The <logMessage> is the name of the handler called by the <log> command. The
37+
default <logMessage> is `log`. If set to empty then the <log> command does not
38+
invoke any handler or evaluate parameters, therefore, allowing for many logs to
39+
be added to scripts for development and an easy low-cost method to turn the
40+
logging off for a release build. The <logMessage> may be set to any handler name,
41+
however, if the handler is not in the message path then use of the <log> command
42+
will throw a `can't find handler` error.
43+
44+
References: log (command), put (command), msgChanged (message)
45+
46+
Tags: debugging
47+

engine/src/debug.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ MCExecContext *MCexecutioncontexts[MAX_CONTEXTS];
6767
uint2 MCnexecutioncontexts = 0;
6868
uint2 MCdebugcontext = MAXUINT2;
6969
Boolean MCmessagemessages = False;
70+
MCNameRef MClogmessage;
7071

7172
////////////////////////////////////////////////////////////////////////////////
7273

engine/src/debug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ extern MCExecContext *MCexecutioncontexts[MAX_CONTEXTS];
9797
extern uint2 MCnexecutioncontexts;
9898
extern uint2 MCdebugcontext;
9999
extern Boolean MCmessagemessages;
100+
extern MCNameRef MClogmessage;
100101

101102
struct MCExecValue;
102103

engine/src/exec-debugging.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,25 @@ void MCDebuggingSetWatchedVariables(MCExecContext& ctxt, MCStringRef p_value)
369369

370370
////////////////////////////////////////////////////////////////////////////////
371371

372+
void MCDebuggingGetLogMessage(MCExecContext& ctxt, MCStringRef& r_value)
373+
{
374+
r_value = MCValueRetain(MCNameGetString(MClogmessage));
375+
}
376+
377+
void MCDebuggingSetLogMessage(MCExecContext& ctxt, MCStringRef p_value)
378+
{
379+
MCNewAutoNameRef t_logmessage;
380+
if (!MCNameCreate(p_value, &t_logmessage))
381+
{
382+
ctxt.Throw();
383+
return;
384+
}
385+
386+
MCValueAssign(MClogmessage, *t_logmessage);
387+
}
388+
389+
////////////////////////////////////////////////////////////////////////////////
390+
372391
void MCDebuggingExecAssert(MCExecContext& ctxt, int type, bool p_eval_success, bool p_result)
373392
{
374393
switch(type)

engine/src/exec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3782,6 +3782,8 @@ void MCDebuggingGetExecutionContexts(MCExecContext& ctxt, MCStringRef& r_value);
37823782
void MCDebuggingGetWatchedVariables(MCExecContext& ctxt, MCStringRef& r_value);
37833783
void MCDebuggingSetWatchedVariables(MCExecContext& ctxt, MCStringRef p_value);
37843784
void MCDebuggingExecPutIntoMessage(MCExecContext& ctxt, MCStringRef value, int where);
3785+
void MCDebuggingGetLogMessage(MCExecContext& ctxt, MCStringRef& r_value);
3786+
void MCDebuggingSetLogMessage(MCExecContext& ctxt, MCStringRef p_value);
37853787

37863788
///////////
37873789

engine/src/globals.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,8 @@ void X_clear_globals(void)
886886
#endif
887887

888888
MCDateTimeInitialize();
889+
890+
MClogmessage = MCNAME("log");
889891
}
890892

891893
/* ---------------------------------------------------------------- */
@@ -1546,6 +1548,8 @@ int X_close(void)
15461548
if (MCcmd != nullptr)
15471549
MCValueRelease(MCcmd);
15481550

1551+
MCValueRelease(MClogmessage);
1552+
15491553
return MCretcode;
15501554
}
15511555

engine/src/lextable.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,7 @@ const LT factor_table[] =
11731173
{"lockupdates", TT_PROPERTY, P_LOCK_UPDATES},
11741174
{"log10", TT_FUNCTION, F_LOG10},
11751175
{"log2", TT_FUNCTION, F_LOG2},
1176+
{"logmessage", TT_PROPERTY, P_LOG_MESSAGE},
11761177
{"long", TT_PROPERTY, P_LONG},
11771178
{"longfilepath", TT_FUNCTION, F_LONG_FILE_PATH},
11781179
{"longwindowtitles", TT_PROPERTY, P_LONG_WINDOW_TITLES},

engine/src/parsedef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@ enum Properties {
11051105
P_EXECUTION_CONTEXTS,
11061106
P_MESSAGE_MESSAGES,
11071107
P_WATCHED_VARIABLES,
1108+
P_LOG_MESSAGE,
11081109
P_ALLOW_INLINE_INPUT,
11091110
P_SSL_CERTIFICATES,
11101111
P_HIDE_BACKDROP,

engine/src/property.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ static MCPropertyInfo kMCPropertyInfoTable[] =
362362
DEFINE_RO_PROPERTY(P_EXECUTION_CONTEXTS, String, Debugging, ExecutionContexts)
363363
DEFINE_RW_PROPERTY(P_BREAK_POINTS, String, Debugging, Breakpoints)
364364
DEFINE_RW_PROPERTY(P_WATCHED_VARIABLES, String, Debugging, WatchedVariables)
365+
DEFINE_RW_PROPERTY(P_LOG_MESSAGE, String, Debugging, LogMessage)
365366

366367
DEFINE_RW_ARRAY_PROPERTY(P_CLIPBOARD_DATA, Any, Pasteboard, ClipboardData)
367368
DEFINE_RW_ARRAY_PROPERTY(P_DRAG_DATA, Any, Pasteboard, DragData)
@@ -860,6 +861,7 @@ Parse_stat MCProperty::parse(MCScriptPoint &sp, Boolean the)
860861
case P_EXECUTION_CONTEXTS:
861862
case P_MESSAGE_MESSAGES:
862863
case P_WATCHED_VARIABLES:
864+
case P_LOG_MESSAGE:
863865
case P_ALLOW_INLINE_INPUT:
864866
case P_ACCEPT_DROP:
865867
case P_ALLOWABLE_DRAG_ACTIONS:

0 commit comments

Comments
 (0)