Re: Implementing another language on luajit - function arguments

  • From: Justin Collins <justincollins@xxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Sat, 02 Nov 2013 17:48:33 -0700

On 10/24/2013 02:54 PM, Raphaël Amiard wrote:
Is there a way to avoid the overhead of creating the args table for
every call? What other optimizations are possible?

 From what I'm seeing you don't need a table, all you need is, well,
runtime checks.

<snip>

Runtime checking the number of args passed is a bit more tricky, but
can still be done easily by adding a parameter to the compiled
function. Our previous example

def f(a=0, b=12):
     # code here

then becomes

function f(num_args, a, b)
     if num_args > 2 then
          raise an error
     end
     if b == No_Arg_Passed then
         b = 15
     end
end

This is a good idea, which I plan on stealing.

-Justin

Other related posts: