Skip to content

Commit bd96dba

Browse files
committed
Export block functions
1 parent 434b29d commit bd96dba

File tree

9 files changed

+137
-135
lines changed

9 files changed

+137
-135
lines changed

include/scratchcpp/compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "enum_bitmask.h"
1010
#include "spimpl.h"
1111

12+
#define BLOCK_EXPORT extern "C" LIBSCRATCHCPP_EXPORT
13+
1214
namespace libscratchcpp
1315
{
1416

src/blocks/controlblocks.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,43 +186,43 @@ CompilerValue *ControlBlocks::compileDeleteThisClone(Compiler *compiler)
186186
return nullptr;
187187
}
188188

189-
extern "C" void control_stop_all(ExecutionContext *ctx)
189+
BLOCK_EXPORT void control_stop_all(ExecutionContext *ctx)
190190
{
191191
ctx->engine()->stop();
192192
}
193193

194-
extern "C" void control_stop_other_scripts_in_target(ExecutionContext *ctx)
194+
BLOCK_EXPORT void control_stop_other_scripts_in_target(ExecutionContext *ctx)
195195
{
196196
Thread *thread = ctx->thread();
197197
ctx->engine()->stopTarget(thread->target(), thread);
198198
}
199199

200-
extern "C" void control_start_wait(ExecutionContext *ctx, double seconds)
200+
BLOCK_EXPORT void control_start_wait(ExecutionContext *ctx, double seconds)
201201
{
202202
ctx->stackTimer()->start(seconds);
203203
ctx->engine()->requestRedraw();
204204
}
205205

206-
extern "C" bool control_stack_timer_elapsed(ExecutionContext *ctx)
206+
BLOCK_EXPORT bool control_stack_timer_elapsed(ExecutionContext *ctx)
207207
{
208208
return ctx->stackTimer()->elapsed();
209209
}
210210

211-
extern "C" void control_create_clone_of_myself(Target *target)
211+
BLOCK_EXPORT void control_create_clone_of_myself(Target *target)
212212
{
213213
if (!target->isStage())
214214
static_cast<Sprite *>(target)->clone();
215215
}
216216

217-
extern "C" void control_create_clone_by_index(ExecutionContext *ctx, double index)
217+
BLOCK_EXPORT void control_create_clone_by_index(ExecutionContext *ctx, double index)
218218
{
219219
Target *target = ctx->engine()->targetAt(index);
220220

221221
if (!target->isStage())
222222
static_cast<Sprite *>(target)->clone();
223223
}
224224

225-
extern "C" void control_create_clone(ExecutionContext *ctx, const StringPtr *spriteName)
225+
BLOCK_EXPORT void control_create_clone(ExecutionContext *ctx, const StringPtr *spriteName)
226226
{
227227
static const StringPtr myself("_myself_");
228228

@@ -239,7 +239,7 @@ extern "C" void control_create_clone(ExecutionContext *ctx, const StringPtr *spr
239239
}
240240
}
241241

242-
extern "C" bool control_delete_this_clone(Target *target)
242+
BLOCK_EXPORT bool control_delete_this_clone(Target *target)
243243
{
244244
if (!target->isStage()) {
245245
Sprite *sprite = static_cast<Sprite *>(target);

src/blocks/eventblocks.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ CompilerValue *EventBlocks::compileWhenKeyPressed(Compiler *compiler)
173173
return nullptr;
174174
}
175175

176-
extern "C" bool event_whentouchingobject_predicate(Target *target, const StringPtr *name)
176+
BLOCK_EXPORT bool event_whentouchingobject_predicate(Target *target, const StringPtr *name)
177177
{
178178
static const StringPtr MOUSE_STR = StringPtr("_mouse_");
179179
static const StringPtr EDGE_STR = StringPtr("_edge_");
@@ -196,7 +196,7 @@ extern "C" bool event_whentouchingobject_predicate(Target *target, const StringP
196196
}
197197
}
198198

199-
extern "C" bool event_whengreaterthan_loudness_predicate(ExecutionContext *ctx, double value)
199+
BLOCK_EXPORT bool event_whengreaterthan_loudness_predicate(ExecutionContext *ctx, double value)
200200
{
201201
if (!EventBlocks::audioInput)
202202
EventBlocks::audioInput = AudioInput::instance().get();
@@ -205,12 +205,12 @@ extern "C" bool event_whengreaterthan_loudness_predicate(ExecutionContext *ctx,
205205
return (audioLoudness->getLoudness() > value);
206206
}
207207

208-
extern "C" bool event_whengreaterthan_timer_predicate(ExecutionContext *ctx, double value)
208+
BLOCK_EXPORT bool event_whengreaterthan_timer_predicate(ExecutionContext *ctx, double value)
209209
{
210210
return ctx->engine()->timer()->value() > value;
211211
}
212212

213-
extern "C" void event_broadcast(ExecutionContext *ctx, const StringPtr *name, bool wait)
213+
BLOCK_EXPORT void event_broadcast(ExecutionContext *ctx, const StringPtr *name, bool wait)
214214
{
215215
Thread *thread = ctx->thread();
216216
IEngine *engine = thread->engine();

src/blocks/listblocks.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ const std::string &ListBlocks::listContentsMonitorName(Block *block)
259259
return empty;
260260
}
261261

262-
extern "C" void data_showlist(Target *target, List *list)
262+
BLOCK_EXPORT void data_showlist(Target *target, List *list)
263263
{
264264
Monitor *monitor = list->monitor();
265265

@@ -289,7 +289,7 @@ extern "C" void data_showlist(Target *target, List *list)
289289
monitor->setVisible(true);
290290
}
291291

292-
extern "C" void data_hidelist(Target *target, List *list)
292+
BLOCK_EXPORT void data_hidelist(Target *target, List *list)
293293
{
294294
Monitor *monitor = list->monitor();
295295

src/blocks/looksblocks.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ CompilerValue *LooksBlocks::compileNextBackdrop(Compiler *compiler)
338338
return nullptr;
339339
}
340340

341-
extern "C" void looks_start_stack_timer(ExecutionContext *ctx, double duration)
341+
BLOCK_EXPORT void looks_start_stack_timer(ExecutionContext *ctx, double duration)
342342
{
343343
ctx->stackTimer()->start(duration);
344344
}
@@ -356,7 +356,7 @@ void looks_show_bubble(Thread *thread, TextBubble::Type type, const StringPtr *m
356356
target->bubble()->setText(u8message);
357357
}
358358

359-
extern "C" bool looks_update_bubble(ExecutionContext *ctx)
359+
BLOCK_EXPORT bool looks_update_bubble(ExecutionContext *ctx)
360360
{
361361
if (ctx->stackTimer()->elapsed()) {
362362
Thread *thread = ctx->thread();
@@ -372,57 +372,57 @@ extern "C" bool looks_update_bubble(ExecutionContext *ctx)
372372
return false;
373373
}
374374

375-
extern "C" void looks_say(ExecutionContext *ctx, const StringPtr *message, bool saveThread)
375+
BLOCK_EXPORT void looks_say(ExecutionContext *ctx, const StringPtr *message, bool saveThread)
376376
{
377377
looks_show_bubble(ctx->thread(), TextBubble::Type::Say, message, saveThread);
378378
}
379379

380-
extern "C" void looks_think(ExecutionContext *ctx, const StringPtr *message, bool saveThread)
380+
BLOCK_EXPORT void looks_think(ExecutionContext *ctx, const StringPtr *message, bool saveThread)
381381
{
382382
looks_show_bubble(ctx->thread(), TextBubble::Type::Think, message, saveThread);
383383
}
384384

385-
extern "C" void looks_show(Sprite *sprite)
385+
BLOCK_EXPORT void looks_show(Sprite *sprite)
386386
{
387387
sprite->setVisible(true);
388388
}
389389

390-
extern "C" void looks_hide(Sprite *sprite)
390+
BLOCK_EXPORT void looks_hide(Sprite *sprite)
391391
{
392392
sprite->setVisible(false);
393393
}
394394

395-
extern "C" void looks_changeeffectby(Target *target, IGraphicsEffect *effect, double change)
395+
BLOCK_EXPORT void looks_changeeffectby(Target *target, IGraphicsEffect *effect, double change)
396396
{
397397
target->setGraphicsEffectValue(effect, target->graphicsEffectValue(effect) + change);
398398
}
399399

400-
extern "C" void looks_seteffectto(Target *target, IGraphicsEffect *effect, double value)
400+
BLOCK_EXPORT void looks_seteffectto(Target *target, IGraphicsEffect *effect, double value)
401401
{
402402
target->setGraphicsEffectValue(effect, value);
403403
}
404404

405-
extern "C" void looks_cleargraphiceffects(Target *target)
405+
BLOCK_EXPORT void looks_cleargraphiceffects(Target *target)
406406
{
407407
target->clearGraphicsEffects();
408408
}
409409

410-
extern "C" void looks_changesizeby(Sprite *sprite, double change)
410+
BLOCK_EXPORT void looks_changesizeby(Sprite *sprite, double change)
411411
{
412412
sprite->setSize(sprite->size() + change);
413413
}
414414

415-
extern "C" void looks_setsizeto(Sprite *sprite, double size)
415+
BLOCK_EXPORT void looks_setsizeto(Sprite *sprite, double size)
416416
{
417417
sprite->setSize(size);
418418
}
419419

420-
extern "C" double looks_size(Sprite *sprite)
420+
BLOCK_EXPORT double looks_size(Sprite *sprite)
421421
{
422422
return sprite->size();
423423
}
424424

425-
extern "C" void looks_set_costume_by_index(Target *target, long index)
425+
BLOCK_EXPORT void looks_set_costume_by_index(Target *target, long index)
426426
{
427427
const int costumeCount = target->costumes().size();
428428

@@ -434,12 +434,12 @@ extern "C" void looks_set_costume_by_index(Target *target, long index)
434434
target->setCostumeIndex(index);
435435
}
436436

437-
extern "C" void looks_nextcostume(Target *target)
437+
BLOCK_EXPORT void looks_nextcostume(Target *target)
438438
{
439439
looks_set_costume_by_index(target, target->costumeIndex() + 1);
440440
}
441441

442-
extern "C" void looks_previouscostume(Target *target)
442+
BLOCK_EXPORT void looks_previouscostume(Target *target)
443443
{
444444
looks_set_costume_by_index(target, target->costumeIndex() - 1);
445445
}
@@ -452,7 +452,7 @@ void looks_randomcostume(Target *target, IRandomGenerator *rng)
452452
looks_set_costume_by_index(target, rng->randintExcept(0, count - 1, target->costumeIndex())); // exclude current costume
453453
}
454454

455-
extern "C" void looks_switchcostumeto(Target *target, const ValueData *costume)
455+
BLOCK_EXPORT void looks_switchcostumeto(Target *target, const ValueData *costume)
456456
{
457457
// https://github.com/scratchfoundation/scratch-vm/blob/8dbcc1fc8f8d8c4f1e40629fe8a388149d6dfd1c/src/blocks/scratch3_looks.js#L389-L413
458458
if (!value_isString(costume)) {
@@ -485,7 +485,7 @@ extern "C" void looks_switchcostumeto(Target *target, const ValueData *costume)
485485
}
486486
}
487487

488-
extern "C" void looks_start_backdrop_scripts(ExecutionContext *ctx, bool wait)
488+
BLOCK_EXPORT void looks_start_backdrop_scripts(ExecutionContext *ctx, bool wait)
489489
{
490490
IEngine *engine = ctx->engine();
491491
Stage *stage = engine->stage();
@@ -495,7 +495,7 @@ extern "C" void looks_start_backdrop_scripts(ExecutionContext *ctx, bool wait)
495495
engine->startBackdropScripts(backdrop->broadcast(), ctx->thread(), wait);
496496
}
497497

498-
extern "C" void looks_switchbackdropto(ExecutionContext *ctx, const ValueData *backdrop)
498+
BLOCK_EXPORT void looks_switchbackdropto(ExecutionContext *ctx, const ValueData *backdrop)
499499
{
500500
Stage *stage = ctx->engine()->stage();
501501

@@ -532,53 +532,53 @@ extern "C" void looks_switchbackdropto(ExecutionContext *ctx, const ValueData *b
532532
}
533533
}
534534

535-
extern "C" void looks_move_to_front(ExecutionContext *ctx)
535+
BLOCK_EXPORT void looks_move_to_front(ExecutionContext *ctx)
536536
{
537537
Target *target = ctx->thread()->target();
538538
ctx->engine()->moveDrawableToFront(target);
539539
}
540540

541-
extern "C" void looks_move_to_back(ExecutionContext *ctx)
541+
BLOCK_EXPORT void looks_move_to_back(ExecutionContext *ctx)
542542
{
543543
Target *target = ctx->thread()->target();
544544
ctx->engine()->moveDrawableToBack(target);
545545
}
546546

547-
extern "C" void looks_move_forward_layers(ExecutionContext *ctx, double layers)
547+
BLOCK_EXPORT void looks_move_forward_layers(ExecutionContext *ctx, double layers)
548548
{
549549
Target *target = ctx->thread()->target();
550550
ctx->engine()->moveDrawableForwardLayers(target, layers);
551551
}
552552

553-
extern "C" void looks_move_backward_layers(ExecutionContext *ctx, double layers)
553+
BLOCK_EXPORT void looks_move_backward_layers(ExecutionContext *ctx, double layers)
554554
{
555555
Target *target = ctx->thread()->target();
556556
ctx->engine()->moveDrawableBackwardLayers(target, layers);
557557
}
558558

559-
extern "C" double looks_backdrop_number(ExecutionContext *ctx)
559+
BLOCK_EXPORT double looks_backdrop_number(ExecutionContext *ctx)
560560
{
561561
return ctx->engine()->stage()->costumeIndex() + 1;
562562
}
563563

564-
extern "C" void looks_backdrop_name(StringPtr *ret, ExecutionContext *ctx)
564+
BLOCK_EXPORT void looks_backdrop_name(StringPtr *ret, ExecutionContext *ctx)
565565
{
566566
const std::string &name = ctx->engine()->stage()->currentCostume()->name();
567567
string_assign_cstring(ret, name.c_str());
568568
}
569569

570-
extern "C" double looks_costume_number(Target *target)
570+
BLOCK_EXPORT double looks_costume_number(Target *target)
571571
{
572572
return target->costumeIndex() + 1;
573573
}
574574

575-
extern "C" void looks_costume_name(StringPtr *ret, Target *target)
575+
BLOCK_EXPORT void looks_costume_name(StringPtr *ret, Target *target)
576576
{
577577
const std::string &name = target->currentCostume()->name();
578578
string_assign_cstring(ret, name.c_str());
579579
}
580580

581-
extern "C" bool looks_backdrop_promise(ExecutionContext *ctx)
581+
BLOCK_EXPORT bool looks_backdrop_promise(ExecutionContext *ctx)
582582
{
583583
if (ctx->engine()->stage()->costumes().size() > 0) {
584584
ctx->setPromise(std::make_shared<Promise>());
@@ -588,7 +588,7 @@ extern "C" bool looks_backdrop_promise(ExecutionContext *ctx)
588588
return false;
589589
}
590590

591-
extern "C" void looks_nextbackdrop(ExecutionContext *ctx)
591+
BLOCK_EXPORT void looks_nextbackdrop(ExecutionContext *ctx)
592592
{
593593
looks_nextcostume(ctx->engine()->stage());
594594
}

0 commit comments

Comments
 (0)