Atoms Crowd  7.0.0
AtomsScriptLang.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015-2024 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 
10 #include "Globals.h"
11 #include <memory>
12 #include <functional>
13 #include <vector>
14 #include <string>
15 
16 namespace Atoms
17 {
19  class ATOMSJIT_EXPORT AtomsScriptLang
20  {
21  public:
22 
23  static AtomsScriptLang& instance();
24 
25  void initialize();
26 
27  std::vector<std::pair<std::string, std::string>> testCode(const std::string& source);
28 
29  bool testCodeWithLog(const std::string& source, const std::function<void(const char*, const char*)>& externalLog);
30 
31  bool addCode(const std::string& name, const std::string& source);
32 
33  bool addCodeWithArgs(const std::string& name, const std::string& source, const std::string& args);
34 
35  void removeCode(const std::string& name);
36 
37  template<typename T>
38  std::function<T> lookup(const std::string& name)
39  {
40  return std::function<T>(reinterpret_cast<T*>(_lookup(name)));
41  }
42 
43  template<typename T>
44  std::function<T> lookup(const std::string& moduleName, const std::string& name)
45  {
46  return std::function<T>(reinterpret_cast<T*>(_lookup(moduleName, name)));
47  }
48 
49  uintptr_t lookupPtr(const std::string& moduleName, const std::string& name)
50  {
51  return _lookup(moduleName, name);
52  }
53 
54  void clear();
55 
56  std::string generateUniqueName();
57 
58  void setLog(void (*callback)(const char*)) { m_log = callback; }
59 
60  void log(const char* msg) { if (m_log) m_log(msg); }
61 
62  void setDefaultArgs(const std::vector<std::string>& args);
63 
64  void addDefaultArgs(const std::vector<std::string>& args);
65 
66  private:
67 
69 
70  ~AtomsScriptLang();
71 
72  AtomsScriptLang(const AtomsScriptLang&) = delete;
73 
74  AtomsScriptLang& operator=(const AtomsScriptLang&) = delete;
75 
76  uintptr_t _lookup(const std::string& name);
77 
78  uintptr_t _lookup(const std::string& moduleName, const std::string& name);
79 
80  private:
81 
82 #ifdef ENABLE_ATOMS_LLVM
83  std::unique_ptr<class AtomsJIT> m_jit;
84 #endif
85 
86  size_t m_unique_identifier;
87 
88  void (*m_log)(const char*);
89  };
90 
91 }
Nurbs curve.
Definition: AtomsScriptLang.h:20
Atoms namespace.
Definition: Agent.h:29