1. Harald Klimach
  2. aotus

Commits

jas43  committed a484cdb

Keep track of whether lua state is open. Function to check if it is open.

  • Participants
  • Parent commits 5a6a178
  • Branches default

Comments (0)

Files changed (1)

File LuaFortran/flu_binding.f90

View file
  • Ignore whitespace
 
   type :: flu_State
     private
-    type(c_ptr) :: state
+    type(c_ptr) :: state => c_null_ptr
   end type flu_State
 
   public :: flu_State
 
-  public :: flu_close
+  public :: flu_close, flu_isopen
   public :: flu_getField, flu_getGlobal, flu_getTable, flu_getTop
   public :: flu_isFunction, flu_isNumber, flu_isTable
   public :: flu_isNone, flu_isNoneOrNil, flu_isNil
     type(flu_State) :: L
 
     call lua_close(L%state)
+    L%state = c_null_ptr
   end subroutine flu_close
 
 
     
     call luaL_openlibs(L%state)
   end subroutine fluL_openlibs
-    
+
+
+  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+  ! Routines for probing the Lua state
+  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+  function flu_isopen(L) result(is_open)
+      logical :: is_open
+      type(flu_State), intent(in) :: L
+
+      is_open = c_associated(L%state)
+  end function flu_isopen
+
+
 end module flu_binding