Skip to content

Commit

Permalink
Add class unregistration test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyong committed Jan 22, 2014
1 parent 812b87d commit 44b9360
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ ____/ \___| _| \___| _| _| \___|

Simple C++11 friendly bindings to Lua.

![Lua logo](http://www.lua.org/images/lua-logo.gif)

## Building

The project requires Cmake > v2.8.11 although an older Cmake is likely
Expand Down Expand Up @@ -104,6 +106,9 @@ assert(result == 10);
You can also register functor objects, lambdas, and any fully
qualified `std::function`. See `test/interop_tests.h` for details.

If we no longer want a function to be accessible, we can unregister it
with `state.Unregister("c_multiply")` for example.

### Registering Object Instances

```c++
Expand Down Expand Up @@ -131,6 +136,9 @@ assert(foo.x == 4);

int result = state.CallField("foo", "double_add", 3);
assert(result == 14);

// If foo goes out of scope, we need to unregister it
state.Unregister("foo");
```
In the above example, the functions `foo.double_add` and `foo.set_x`
Expand Down
3 changes: 2 additions & 1 deletion test/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ static std::vector<bool(*)()> tests = {
test_c_fun_destructor,
test_register_class,
test_mutate_instance,
test_multiple_methods
test_multiple_methods,
test_unregister_instance
};


Expand Down
12 changes: 12 additions & 0 deletions test/class_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,15 @@ bool test_multiple_methods() {
const int answer = state.CallField<int>("foo_instance", "double_add", 3);
return (answer == 14);
}

bool test_unregister_instance() {
Foo foo_instance(1);
sel::State state;
state.Register("foo_instance",
foo_instance,
std::make_pair("double_add", &Foo::DoubleAdd),
std::make_pair("set_x", &Foo::SetX));
bool exists = !state.CheckNil("foo_instance");
state.Unregister("foo_instance");
return exists && state.CheckNil("foo_instance");
}

0 comments on commit 44b9360

Please sign in to comment.