szaszm commented on a change in pull request #1237:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1237#discussion_r783002744



##########
File path: extensions/script/ExecuteScript.cpp
##########
@@ -116,6 +121,9 @@ void ExecuteScript::onTrigger(const 
std::shared_ptr<core::ProcessContext> &conte
       throw std::runtime_error("No script engine available");
     }
 
+    if (module_directory_.size()) {
+      
engine->setModuleDirectories(utils::StringUtils::splitAndTrimRemovingEmpty(module_directory_,
 ","));

Review comment:
       Not sure if you want to support weird filenames, just want to point out 
that filenames can start/end with spaces or contain commas.

##########
File path: extensions/script/ScriptEngine.h
##########
@@ -41,7 +43,14 @@ class ScriptEngine {
    */
   virtual void evalFile(const std::string &file_name) = 0;
 
+  void setModuleDirectories(std::vector<std::string>&& module_dirs) {
+    module_directories_ = std::move(module_dirs);
+  }
+
   virtual ~ScriptEngine() = default;
+
+ protected:
+  std::vector<std::string> module_directories_;

Review comment:
       This should probably be a vector of `std::filesystem::path` for stronger 
typing.

##########
File path: extensions/script/lua/LuaScriptEngine.cpp
##########
@@ -65,15 +65,32 @@ LuaScriptEngine::LuaScriptEngine()
 
 void LuaScriptEngine::eval(const std::string &script) {
   try {
-    lua_.script(script, sol::script_throw_on_error);
+    if (!module_directories_.empty()) {
+      auto appended_script = script;
+      for (const auto& module_dir : module_directories_) {
+        appended_script = "package.path = package.path .. \";" + module_dir + 
"/?.lua\"\n" + script;
+      }
+      lua_.script(appended_script, sol::script_throw_on_error);

Review comment:
       Please extract this logic and reuse it in `evalFile`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to