jas43 avatar jas43 committed 449bc76

get_table_userdata: getting a userdata value from a table.

Comments (0)

Files changed (1)

source/aot_table_module.f90

     module procedure get_table_long
     module procedure get_table_string
     module procedure get_table_logical
+    module procedure get_table_userdata
   end interface
 
   !> Set a value in a table.
     module procedure get_table_long
     module procedure get_table_string
     module procedure get_table_logical
+    module procedure get_table_userdata
   end interface
 
   !> This interface enables the simple creation of uniform one dimensional
   end subroutine get_table_logical
 
 
+  !> Retrieve a userdata value (generic C pointer) from a table.
+  subroutine get_table_userdata(val, ErrCode, L, thandle, key, pos, &
+    &                          default)
+
+    use, intrinsic :: iso_c_binding, only: c_ptr
+
+    type(flu_State) :: L !< Handle to the Lua script.
+
+    !> Handle to the table to look the value up in.
+    integer, intent(in), optional :: thandle
+
+    !> Value of the table entry if it exists.
+    type(c_ptr), intent(out) :: val
+
+    !> Error code to indicate what kind of problem might have occured.
+    integer, intent(out) :: ErrCode
+
+    !> Name of the entry to look for.
+    !!
+    !! Key and pos are both optional, however at least one of them has to be
+    !! supplied.
+    !! The key takes precedence over the pos if both are given.
+    character(len=*), intent(in), optional :: key
+
+    !> Position of the entry to look for in the table.
+    !!
+    !! It allows the access to unnamed arrays in the Lua tables.
+    integer, intent(in), optional :: pos
+
+    !> Some default value, that should be used, if the variable is not set in
+    !! the Lua script.
+    type(c_ptr), intent(in), optional :: default
+
+    logical :: valid_args
+
+    valid_args = .true.
+    if (present(thandle)) then
+      call aot_table_push(L=L, thandle=thandle, &
+        &                 key=key, pos=pos)
+    else
+      if (present(key)) then
+        call flu_getglobal(L, key)
+      else
+        valid_args = .false.
+      end if
+    end if
+    if (valid_args) then
+      call aot_top_get_val(val, ErrCode, L, default)
+    else
+      ErrCode = ibSet(0, aoterr_NonExistent)
+      ErrCode = ibSet(ErrCode, aoterr_Fatal)
+    end if
+
+  end subroutine get_table_userdata
+
+
   !> Retrieve a string from a table.
   subroutine get_table_string(val, ErrCode, L, thandle, key, pos, &
     &                         default)
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.