-
-
Notifications
You must be signed in to change notification settings - Fork 35
feat: LuaCallable #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: LuaCallable #224
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6140dbe
feat: LuaCallable
illarn 4be3b23
Merge branch 'main' of https://github.com/gilzoide/lua-gdextension
illarn 8b013ba
fix: fixed callable test
illarn af6d7ea
feat: callable from lua function lua ls definition
illarn 25b1cec
fixed brackets
illarn bf6fc53
fixes from the feedback
illarn c908c65
fixed callable test
illarn d5a021b
included callable from lua function into README
illarn aba225e
removed leftover virtual from LuaCallable's methods
illarn adabff8
removed excessive type specifier
illarn 528d48a
aded .clang-format
illarn 3b00277
fixed callable test
illarn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| BasedOnStyle: LLVM | ||
| IndentWidth: 4 | ||
| TabWidth: 4 | ||
| UseTab: Always | ||
| ColumnLimit: 200 | ||
| AccessModifierOffset: -4 | ||
| PointerAlignment: Left | ||
| FixNamespaceComments: false | ||
|
|
||
| IncludeBlocks: Regroup | ||
| SortIncludes: CaseSensitive | ||
| IncludeCategories: | ||
| - Regex: '^"[A-Za-z]' | ||
| Priority: 1 | ||
| SortPriority: 1 | ||
| - Regex: '^"\.\.' | ||
| Priority: 1 | ||
| SortPriority: 2 | ||
| - Regex: '^<' | ||
| Priority: 3 | ||
| SortPriority: 3 | ||
|
|
||
| BreakBeforeBraces: Attach | ||
| AllowShortBlocksOnASingleLine: Never | ||
| AllowShortFunctionsOnASingleLine: None | ||
|
|
||
| BreakConstructorInitializers: BeforeColon | ||
| PackConstructorInitializers: Never |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #include "LuaCallable.hpp" | ||
| #include "godot_cpp/variant/callable.hpp" | ||
| #include "godot_cpp/variant/variant.hpp" | ||
|
|
||
| namespace luagdextension { | ||
|
|
||
| LuaCallable::CompareEqualFunc LuaCallable::get_compare_equal_func() const { | ||
| return nullptr; | ||
| } | ||
|
|
||
| LuaCallable::CompareLessFunc LuaCallable::get_compare_less_func() const { | ||
| return nullptr; | ||
| } | ||
|
|
||
| bool LuaCallable::is_valid() const { | ||
| return _lua_func->get_function().valid(); | ||
| } | ||
|
|
||
| ObjectID LuaCallable::get_object() const { | ||
| return {}; | ||
| } | ||
|
|
||
| String LuaCallable::get_as_text() const { | ||
| return "<LuaCallable>"; | ||
| } | ||
|
|
||
| uint32_t LuaCallable::hash() const { | ||
| return get_as_text().hash(); | ||
| } | ||
|
|
||
| void LuaCallable::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, GDExtensionCallError &r_call_error) const { | ||
| r_return_value = _lua_func->invoke(p_arguments, p_argcount, r_call_error); | ||
| } | ||
|
|
||
| Variant LuaCallable::construct(sol::function func) { | ||
| return Variant{Callable{memnew(LuaCallable(func))}}; | ||
| }; | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #pragma once | ||
|
|
||
| #include "../LuaFunction.hpp" | ||
|
|
||
| namespace luagdextension { | ||
|
|
||
| using namespace godot; | ||
|
|
||
| class LuaCallable : public CallableCustom { | ||
| Ref<LuaFunction> _lua_func; | ||
| public: | ||
| explicit LuaCallable(sol::protected_function func) : _lua_func{LuaObject::wrap_object<LuaFunction>(func)} {}; | ||
| ~LuaCallable() = default; | ||
|
|
||
| bool is_valid() const override; | ||
| String get_as_text() const override; | ||
| ObjectID get_object() const override; | ||
| CompareEqualFunc get_compare_equal_func() const override; | ||
| CompareLessFunc get_compare_less_func() const override; | ||
| uint32_t hash() const override; | ||
| void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, GDExtensionCallError &r_call_error) const override; | ||
| static Variant construct(sol::function func); | ||
| }; | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,12 @@ | ||
| local callable = Callable(OS, "get_name") | ||
| assert(callable() == OS:get_name()) | ||
| local a = 1 | ||
| local custom_callable = Callable(function(val) | ||
| a = a + val | ||
| return a | ||
| end) | ||
| local result = custom_callable(5) | ||
| assert(a == 6 and result == 6) | ||
| custom_callable = custom_callable:bind(1) | ||
| custom_callable() | ||
| assert(a == 7) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also please use
sol::protected_functionhere instead ofsol::function.