}
;
-library: T_LIBRARY T_STRING
- {
- context->HandleLibrary($2);
- free($2);
- }
- ;
-
identifier: T_IDENTIFIER
| T_STRING
;
| T_SET_BINARY_OR
;
-lterm: library
+lterm: T_LIBRARY rterm
{
- $$ = MakeLiteral(); // ASTify this
+ $$ = new LibraryExpression($2, @$);
}
| rterm combined_set_op rterm
{
return new DictExpression(expressions);
}
-/**
- * Handles the library directive.
- *
- * @param library The name of the library.
- */
-void ConfigCompiler::HandleLibrary(const String& library)
-{
- Loader::LoadExtensionLibrary(library);
-}
-
/**
* Compiles a stream.
*
Expression *HandleInclude(const String& include, bool search, const DebugInfo& debuginfo = DebugInfo());
Expression *HandleIncludeRecursive(const String& path, const String& pattern, const DebugInfo& debuginfo = DebugInfo());
Expression *HandleIncludeZones(const String& tag, const String& path, const String& pattern, const DebugInfo& debuginfo = DebugInfo());
- void HandleLibrary(const String& library);
size_t ReadInput(char *buffer, size_t max_bytes);
void *GetScanner(void) const;
#include "base/logger.hpp"
#include "base/exception.hpp"
#include "base/scriptglobal.hpp"
+#include "base/loader.hpp"
#include <boost/foreach.hpp>
#include <boost/exception_ptr.hpp>
#include <boost/exception/errinfo_nested_exception.hpp>
return VMOps::For(frame, m_FKVar, m_FVVar, valueres.GetValue(), m_Expression, m_DebugInfo);
}
+ExpressionResult LibraryExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
+{
+ if (frame.Sandboxed)
+ BOOST_THROW_EXCEPTION(ScriptError("Loading libraries is not allowed in sandbox mode.", m_DebugInfo));
+
+ ExpressionResult libres = m_Operand->Evaluate(frame, dhint);
+ CHECK_RESULT(libres);
+
+ Loader::LoadExtensionLibrary(libres.GetValue());
+
+ return Empty;
+}
+
Expression *m_Operand2;
};
-
class I2_CONFIG_API VariableExpression : public DebuggableExpression
{
public:
Expression *m_Expression;
};
+class I2_CONFIG_API LibraryExpression : public UnaryExpression
+{
+public:
+ LibraryExpression(Expression *expression, const DebugInfo& debugInfo = DebugInfo())
+ : UnaryExpression(expression, debugInfo)
+ { }
+
+protected:
+ virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
+};
+
}
#endif /* EXPRESSION_H */