# aot_fun_top Function

## public function aot_fun_top(L) result(fun)

Return the stack of the top as a function.

If it actually is not a Lua function, the returned handle will be 0.

### Arguments

Type IntentOptional AttributesName
type(flu_state) :: L

Handle for the Lua script.

### Return Value type(aot_fun_type)

Handle to the function on the top of the stack.

## Source Code

  function aot_fun_top(L) result(fun)
type(flu_state) :: L !! Handle for the Lua script.

!> Handle to the function on the top of the stack.
type(aot_fun_type) :: fun

fun%handle = 0
fun%arg_count = 0
if (flu_isFunction(L, -1)) then
! Keep a handle to this function.
fun%handle = flu_gettop(L)
fun%id = flu_topointer(L, -1)
! Push a copy of the function right after it, the function will
! be popped from the stack upon execution. Thus, this copy is
! used to ensure the reference to the function is kept across
! several executions of the function.
call flu_pushvalue(L, -1)
end if
end function aot_fun_top