Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To be honest: I don't think it's a good idea as you described, but does have potential.</p> <p>This limits you with an 'annoying' burden of C++'s static number of arguments, which is may or may not what you want in your language.</p> <p>Imagine this - you want to represent a function:</p> <pre><code>VM::allFunctions["functionName"](variable1); </code></pre> <p>But that function takes two arguments! How do we define a dynamic-args function? With "<code>...</code>" - that means <code>stdargs.h</code> and <code>va_list</code>. unfortunately, va_list has disadvantages - you have to supply an extra variable that will somehow be of an information <em>to you</em> of how many variables are there, so we change our fictional function call to:</p> <pre><code>VM::allFunctions["functionName"](1, variable1); VM::allFunctions["functionWithtwoArgs"](2, variable1, variable2); </code></pre> <p>That brings you to a new problem - During runtime, there is <strong>no way to pass multiple arguments</strong>! so we will have to combine those arguments into something that can be defined and used during runtime, let's define it (hypothetically) as </p> <pre><code>typedef std::vector&lt;Variable* &gt; VariableList; </code></pre> <p>And our call is now:</p> <pre><code>VM::allFunctions["functionName"](varList); VM::allFunctions["functionWithtwoArgs"](varList); </code></pre> <p>Now we get into 'scopes' - You cannot 'execute' a function without a scope - especially in embedded scripting languages where you can have <em>several</em> virtual machines (sandboxing, etc...), so we'll have to have a <code>Scope</code> type, and that changes the hypothetical call to:</p> <pre><code>currentVM-&gt;allFunctions["functionName_twoArgs"].call(varList, currentVM-&gt;currentScope); </code></pre> <p>I could continue on and on, but I think you get the point of my answer - C++ doesn't like dynamic languages, and it would most likely not change to fit it, as it will most likely change the ABI as well.</p> <p>Hopefully this will take you to the right direction.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload