jas43 avatar jas43 committed f7d6a9a

Procedure to create flu_state from a pointer to an existing Lua state.

This allows flu bindings to be used from a Fortran procedure which is called
directly from Lua and hence has the interface

function callable_from_lua(lua_state) result(val)
use, intrinsic :: iso_c_binding, only: c_ptr
type(c_ptr), value :: lua_state
integer(c_int) :: val
end function

Comments (0)

Files changed (1)

LuaFortran/flu_binding.f90

   public :: flu_pushvalue
 
   public :: fluL_loadfile, fluL_newstate, fluL_openlibs, fluL_loadstring
+  public :: flu_copyptr
 
   interface flu_pushnumber
     module procedure flu_pushreal
     call luaL_openlibs(L%state)
   end subroutine fluL_openlibs
 
+  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+  ! Routines for using existing Lua states with 
+  ! flu_binding
+  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+  function flu_copyptr(lua_state) result(L)
+      ! WARNING: this copies the pointer to an existing Lua state, not the Lua
+      ! state itself.  Modifying L via the flu bindings will modify the same Lua
+      ! state as pointed to by lua_state.
+      type(flu_State) :: L
+      type(c_ptr), intent(in) :: lua_state
+      L%state = lua_state
+  end function flu_copyptr
 
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! Routines for probing the Lua state
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.