Skip to content

Commit b2adeda

Browse files
committed
[[ Bug 20567 ]] Add 'the caller' LCB syntax
1 parent 4d43131 commit b2adeda

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

docs/lcb/notes/20567.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# LiveCode Builder Language
2+
3+
## `the caller` syntax
4+
`the caller` syntax has been added to the engine module. It
5+
returns the script object which called a the handler at the
6+
beginning of the current chain of LiveCode Builder handler
7+
execution.

engine/src/engine.lcb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public foreign handler MCEngineExecSendWithArguments(in pIsFunction as CBool, in
5858
public foreign handler MCEngineExecPost(in pMessage as String) returns nothing binds to "<builtin>"
5959
public foreign handler MCEngineExecPostWithArguments(in pMessage as String, in pArguments as optional List) returns nothing binds to "<builtin>"
6060

61+
public foreign handler MCEngineEvalCaller(out rObject as ScriptObject) returns nothing binds to "<builtin>"
62+
6163
public foreign handler MCEngineEvalMessageWasHandled(out pHandled as CBool) returns nothing binds to "<builtin>"
6264
public foreign handler MCEngineEvalMessageWasNotHandled(out pHandled as CBool) returns nothing binds to "<builtin>"
6365
public foreign handler MCEngineExecExecuteScript(in pScript as String) returns any binds to "<builtin>"
@@ -397,6 +399,27 @@ begin
397399
MCEngineEvalMessageWasNotHandled(output)
398400
end syntax
399401

402+
/**
403+
Summary: The caller's script object
404+
405+
Example:
406+
public handler NotifyMe() returns nothing
407+
post "notify" to the caller
408+
end handler
409+
410+
Description:
411+
Returns the script object which called the handler at the beginning
412+
of the current chain of LiveCode Builder handler execution.
413+
414+
Tags: Script Engine
415+
*/
416+
417+
syntax Caller is expression
418+
"the" "caller"
419+
begin
420+
MCEngineEvalCaller(output)
421+
end syntax
422+
400423
/**
401424
Summary: Executes some LiveCode script.
402425
Script: The script to execute.

engine/src/module-engine.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,12 @@ extern "C" MC_DLLEXPORT_DEF void MCEngineEvalMessageWasNotHandled(bool& r_not_ha
602602
r_not_handled = !t_handled;
603603
}
604604

605+
extern MCExecContext *MCECptr;
606+
extern "C" MC_DLLEXPORT_DEF void MCEngineEvalCaller(MCScriptObjectRef& r_script_object)
607+
{
608+
if (!MCEngineScriptObjectCreate(MCECptr->GetObject(), 0, r_script_object))
609+
return;
610+
}
605611
////////////////////////////////////////////////////////////////////////////////
606612

607613
static MCValueRef

tests/lcs/core/engine-lcb/_engine.lcb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,7 @@ public handler TestExtensionLog_DeletedScriptObject()
4949
log tScriptObject
5050
end handler
5151

52+
public handler TestEngine_Caller(in pCallback as String)
53+
send pCallback to the caller
54+
end handler
5255
end library

tests/lcs/core/engine-lcb/engine.livecodescript

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,20 @@ on TestExtensionLogScriptObject
136136
TestDiagnostic sLastLog
137137
TestAssert "extension log deleted scriptobject", sLastLog is "<deleted script object>"
138138
end TestExtensionLogScriptObject
139+
140+
local sCallbackTarget
141+
on CallerCallback
142+
TestDiagnostic "called"
143+
put the long id of the target into sCallbackTarget
144+
end CallerCallback
145+
146+
on TestEngineCaller
147+
local tButton
148+
create button
149+
put it into tButton
150+
set the script of tButton to "on doTest;TestEngine_Caller" \
151+
&& quote & "CallerCallback" & quote & ";end doTest"
152+
send "doTest" to tButton
153+
TestAssert "library handler can get caller", \
154+
the long id of sCallbackTarget is the long id of tButton
155+
end TestEngineCaller

0 commit comments

Comments
 (0)