File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,28 +19,14 @@ ec.callbackRespondsToKey = function(key)
1919 return key == " lua"
2020end
2121
22- useStrings = true
23-
24- -- Use strings.
25- if (useStrings ) then
26- ec .callbackCall = function (key , values )
27- printValues (" Inside normal callback" , values )
28- return values
29- -- return {"Z", "A"}
30- end
31- -- Use vector.
32- else
33- ec .callbackCallVector = function (key , vector )
34- printValues (" Inside vector callback" , vector .values )
35- v = Vector .new ()
36- v :setValues ({" Z" , " A" })
37- return v
38- end
22+ ec .callbackCall = function (key , values )
23+ printValues (" Inside callback" , values )
24+ return {" Z" , " A" }
3925end
4026
4127-- Add ec as Environment client.
4228env :addClient (ec )
4329
4430-- Call newly registered module.
4531values = env :call (" lua" , {" X" , " Y" })
46- printValues (" Values after calling 'lua'" , values )
32+ printValues (" Calling 'lua'" , values )
Original file line number Diff line number Diff line change 66#include < vector>
77
88typedef std::string String;
9-
109typedef std::vector<String> Strings;
1110
1211String stringsToString (const Strings &strings)
Original file line number Diff line number Diff line change 33#define CPP_CALLBACK_SCRIPT_ENVIRONMENT_CLIENT_H
44
55#include " Common.h"
6- #include " Vector.h"
76
87#include < cstdio>
98#include < functional>
@@ -19,14 +18,9 @@ class EnvironmentClient
1918 typedef std::function<Strings (const String &, const Strings &)> CallbackCall;
2019 CallbackCall callbackCall;
2120
22- // Callback for 'call' method using Vector.
23- typedef std::function<Vector (const String &, const Vector &)> CallbackCallVector;
24- CallbackCallVector callbackCallVector;
25-
2621 EnvironmentClient () :
2722 callbackRespondsToKey (nullptr ),
28- callbackCall (nullptr ),
29- callbackCallVector (nullptr ) { }
23+ callbackCall (nullptr ) { }
3024 ~EnvironmentClient () { }
3125
3226 bool respondsToKey (const String &key)
@@ -40,19 +34,10 @@ class EnvironmentClient
4034 }
4135 Strings call (const String &key, const Strings &values)
4236 {
43- // Strings version.
4437 if (this ->callbackCall )
4538 {
4639 return this ->callbackCall (key, values);
4740 }
48- // Vector version.
49- else if (this ->callbackCallVector )
50- {
51- Vector in;
52- in.values = values;
53- Vector out = this ->callbackCallVector (key, in);
54- return out.values ;
55- }
5641 printf (
5742 " EnvironmentClient.call(%s, %s). provide callback!\n " ,
5843 key.c_str (),
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ void runSol(const char *fileName)
7676 }
7777 );
7878
79- #define REGISTER_PLAIN_CALLBACK
79+ // #define REGISTER_PLAIN_CALLBACK
8080
8181 // Register environment client class.
8282 lua.new_usertype <EnvironmentClient>(
@@ -96,21 +96,9 @@ void runSol(const char *fileName)
9696 };
9797 }),
9898#endif // REGISTER_PLAIN_CALLBACK
99- " callbackCallVector" , &EnvironmentClient::callbackCallVector,
10099 " callbackRespondsToKey" , &EnvironmentClient::callbackRespondsToKey
101100 );
102101
103- // Register vector class.
104- lua.new_usertype <Vector>(
105- " Vector" ,
106- " values" , &Vector::values,
107- " setValues" ,
108- [](Vector &vector, sol::nested<Strings> values)
109- {
110- return vector.setValues (values);
111- }
112- );
113-
114102 // Load and execute script.
115103 lua.script_file (fileName);
116104}
You can’t perform that action at this time.
0 commit comments