diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2021-04-28 16:44:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-28 16:44:59 +0200 |
commit | f505a2679808ddb95a552d9ad8ce9a0f9aa3b285 (patch) | |
tree | 87e54337831be88c37e0c252c57f9a466b8fe2c6 /modules/gdscript/gdscript_byte_codegen.cpp | |
parent | 4ea73633047e5b52dee38ffe0b958f60e859d5b7 (diff) | |
parent | 9ed0f0384cd73921f2c85d1e030fbb596b0954ea (diff) | |
download | redot-engine-f505a2679808ddb95a552d9ad8ce9a0f9aa3b285.tar.gz |
Merge pull request #47454 from vnen/gdscript-lambda
Diffstat (limited to 'modules/gdscript/gdscript_byte_codegen.cpp')
-rw-r--r-- | modules/gdscript/gdscript_byte_codegen.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_byte_codegen.cpp b/modules/gdscript/gdscript_byte_codegen.cpp index 89c5f5482b..0da99ccee3 100644 --- a/modules/gdscript/gdscript_byte_codegen.cpp +++ b/modules/gdscript/gdscript_byte_codegen.cpp @@ -383,6 +383,18 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() { function->_methods_count = 0; } + if (lambdas_map.size()) { + function->lambdas.resize(lambdas_map.size()); + function->_lambdas_ptr = function->lambdas.ptrw(); + function->_lambdas_count = lambdas_map.size(); + for (const Map<GDScriptFunction *, int>::Element *E = lambdas_map.front(); E; E = E->next()) { + function->lambdas.write[E->get()] = E->key(); + } + } else { + function->_lambdas_ptr = nullptr; + function->_lambdas_count = 0; + } + if (debug_stack) { function->stack_debug = stack_debug; } @@ -1118,6 +1130,17 @@ void GDScriptByteCodeGenerator::write_call_script_function(const Address &p_targ append(p_function_name); } +void GDScriptByteCodeGenerator::write_lambda(const Address &p_target, GDScriptFunction *p_function, const Vector<Address> &p_captures) { + append(GDScriptFunction::OPCODE_CREATE_LAMBDA, 1 + p_captures.size()); + for (int i = 0; i < p_captures.size(); i++) { + append(p_captures[i]); + } + + append(p_target); + append(p_captures.size()); + append(p_function); +} + void GDScriptByteCodeGenerator::write_construct(const Address &p_target, Variant::Type p_type, const Vector<Address> &p_arguments) { // Try to find an appropriate constructor. bool all_have_type = true; |