aot_fun_put_top Subroutine

private subroutine aot_fun_put_top(L, fun)

Put the top of the stack as argument into the list of arguments for the function.

Arguments

Type IntentOptional Attributes Name
type(flu_State) :: L

Handle for the Lua script.

type(aot_fun_type) :: fun

Handle of the function, this argument should be put into.


Calls

proc~~aot_fun_put_top~~CallsGraph proc~aot_fun_put_top aot_fun_put_top proc~flu_gettop flu_gettop proc~aot_fun_put_top->proc~flu_gettop proc~flu_insert flu_insert proc~aot_fun_put_top->proc~flu_insert interface~lua_gettop lua_gettop proc~flu_gettop->interface~lua_gettop interface~lua_rotate lua_rotate proc~flu_insert->interface~lua_rotate

Called by

proc~~aot_fun_put_top~~CalledByGraph proc~aot_fun_put_top aot_fun_put_top interface~aot_fun_put aot_fun_put interface~aot_fun_put->proc~aot_fun_put_top

Source Code

  subroutine aot_fun_put_top(L, fun)
    type(flu_state) :: L !! Handle for the Lua script.

    !> Handle of the function, this argument should be put into.
    type(aot_fun_type) :: fun

    integer :: curtop

    ! Only do something, if the function is actually properly defined.
    if (fun%handle /= 0) then

      ! Get position of current top of the stack.
      curtop = flu_gettop(L)

      ! If the function was executed before this call, it has to be
      ! reset.
      if (fun%arg_count == -1) then
        ! Only procede, if curtop is exactly one above the function reference,
        ! that is after executing the function previously, only one item was
        ! put into the stack, which should now be used as an argument.
        if (curtop == fun%handle+1) then
          ! Push a copy of the function itself on the stack again, before
          ! adding arguments, to savely survive popping of the function
          ! upon execution. (insert this copy before the already added argument)
          call flu_insert(L, fun%handle+1)
          ! Increase the argument count to 0 again (really start counting
          ! arguments afterwards.
          fun%arg_count = fun%arg_count+1
          curtop = curtop + 1
        end if
      end if

      ! Only proceed, if the current top is actually a new argument (that is, it
      ! is especially not the function copy at fun%handle + 1 itself).
      if ((curtop - fun%arg_count) == (fun%handle + 2)) then
        fun%arg_count = fun%arg_count+1
      end if
    end if

  end subroutine aot_fun_put_top