MCPcopy Create free account
hub / github.com/ThePhD/sol2 / main

Function main

examples/source/protect.cpp:5–26  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3
4
5int main(int, char*[]) {
6
7 struct protect_me {
8 int gen(int x) {
9 return x;
10 }
11 };
12
13 sol::state lua;
14 lua.open_libraries(sol::lib::base);
15 lua.new_usertype<protect_me>(
16 "protect_me", "gen", sol::protect(&protect_me::gen));
17
18 lua.script(R"__(
19 pm = protect_me.new()
20 value = pcall(pm.gen,"wrong argument")
21 )__");
22 bool value = lua["value"];
23 SOL_ASSERT(!value);
24
25 return 0;
26}

Callers

nothing calls this directly

Calls 3

protectFunction · 0.85
open_librariesMethod · 0.80
scriptMethod · 0.80

Tested by

no test coverage detected