Skip to content

Commit

Permalink
Add selector move constructor to address #63.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyong committed Feb 22, 2015
1 parent 6af4df6 commit cf0c718
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
11 changes: 11 additions & 0 deletions include/selene/Selector.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ class Selector {
_functor(other._functor)
{}

Selector(Selector&& other)
: _state(other._state),
_registry(other._registry),
_name(other._name),
_traversal(other._traversal),
_get(other._get),
_put(other._put),
_functor(other._functor) {
other._functor = nullptr;
}

~Selector() {
// If there is a functor is not empty, execute it and collect no args
if (_functor) {
Expand Down
3 changes: 2 additions & 1 deletion test/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ static TestMap tests = {
{"test_cache_selector_field_assignment", test_cache_selector_field_assignment},
{"test_cache_selector_field_access", test_cache_selector_field_access},
{"test_cache_selector_function", test_cache_selector_function},
{"test_function_should_run_once", test_function_should_run_once},

{"test_register_class", test_register_class},
{"test_get_member_variable", test_get_member_variable},
Expand Down Expand Up @@ -146,5 +147,5 @@ int main() {

// For debugging anything in particular, you can run an individual
//test like so:
//ExecuteTest("test_metatable_ptr_member");
//ExecuteTest("test_function_should_run_once");
}
7 changes: 7 additions & 0 deletions test/selector_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,10 @@ bool test_cache_selector_function(sel::State &state) {
s();
return state["global1"] == 8;
}

bool test_function_should_run_once(sel::State &state) {
state.Load("../test/test.lua");
auto should_run_once = state["should_run_once"];
should_run_once();
return state["should_be_one"] == 1;
}
6 changes: 6 additions & 0 deletions test/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@ end

function set_global()
global1 = 8
end

should_be_one = 0

function should_run_once()
should_be_one = should_be_one + 1
end

0 comments on commit cf0c718

Please sign in to comment.