TorqueScript  0.2
math.hpp
1 
15 #pragma once
16 
17 #include <memory>
18 #include <iostream>
19 #include <stdexcept>
20 
21 #include <torquescript/nativefunction.hpp>
22 #include <torquescript/executionscope.hpp>
23 #include <torquescript/interpreter.hpp>
24 #include <torquescript/executionstate.hpp>
25 #include <torquescript/storedvaluestack.hpp>
26 #include <torquescript/consoleobject.hpp>
27 #include <torquescript/fileobject.hpp>
28 
29 namespace TorqueScript
30 {
31  static void GetRandomBuiltIn(std::shared_ptr<ConsoleObject> thisObject, std::shared_ptr<ExecutionState> state, const std::size_t argumentCount)
32  {
33  StoredValueStack& stack = state->mExecutionScope.getStack();
34 
35  // FIXME: If argC == 1, generate int between 0 and value, if argC == 2, generate int between min and max
36  const float result = (float)std::rand() / RAND_MAX;
37  stack.push_back(StoredValue(result));
38  }
39 
40  static void registerMathLibrary(Interpreter* interpreter)
41  {
42  interpreter->addFunction(std::shared_ptr<Function>(new NativeFunction(GetRandomBuiltIn, PACKAGE_EMPTY, NAMESPACE_EMPTY, "getRandom")));
43  }
44 }
Definition: ast.hpp:28