• R/O
  • SSH

main: 提交

Main development repository for Aotus.


Commit MetaInfo

修訂f91631b6b2453ee4c39107d3501c2adfe9fb162e (tree)
時間2019-04-25 18:15:24
作者Nick Papior <nickpapior@gmai...>
CommiterNick Papior

Log Message

enh: enabled getting user-data back (c_ptr)

Change Summary

差異

diff -r cf928882e836 -r f91631b6b245 source/aot_table_module.f90
--- a/source/aot_table_module.f90 Fri Feb 10 14:31:17 2017 +0100
+++ b/source/aot_table_module.f90 Thu Apr 25 11:15:24 2019 +0200
@@ -69,6 +69,7 @@
6969 module procedure set_table_long
7070 module procedure set_table_string
7171 module procedure set_table_logical
72+ module procedure set_table_userdata
7273 end interface
7374
7475 !> Get a value from the Lua script.
@@ -892,6 +893,53 @@
892893
893894 end subroutine set_table_string
894895
896+ !> Put user-data pointer into a table.
897+ subroutine set_table_userdata(val, L, thandle, key, pos)
898+ use, intrinsic :: iso_c_binding, only: c_ptr
899+
900+ type(flu_State) :: L !! Handle to the Lua script.
901+
902+ !> Handle to the table to look the value up in.
903+ integer, intent(in) :: thandle
904+
905+ !> Pointer to set in the table.
906+ type(c_ptr), intent(in) :: val
907+
908+ !> Name of the entry to set.
909+ !!
910+ !! Key and pos are both optional, however at least one of them has to be
911+ !! supplied.
912+ !! The key takes precedence over the pos if both are given.
913+ character(len=*), intent(in), optional :: key
914+
915+ !> Position of the entry to set in the table.
916+ !!
917+ !! It allows the access to unnamed arrays in the Lua tables.
918+ integer, intent(in), optional :: pos
919+
920+ if (thandle > 0) then
921+ if (present(key)) then
922+ ! If there is a key, use that.
923+ ! First put the value on the top of the stack
924+ call flu_pushlightuserdata(L, val)
925+ ! Now put it into the table
926+ call flu_setField(L, thandle, trim(key))
927+ else
928+ ! No key given, try to put the value by position
929+ if (present(pos)) then
930+ ! First put the index, where to write the value into the table, on the
931+ ! stack.
932+ call flu_pushInteger(L, pos)
933+ ! Now put the actual value on the top of the stack.
934+ call flu_pushlightuserdata(L, val)
935+ ! Get the two entries from the stack into the table.
936+ call flu_setTable(L, thandle)
937+ end if
938+ end if
939+ end if
940+
941+ end subroutine set_table_userdata
942+
895943
896944 !> This subroutine takes a one dimensional array, and puts it as a table
897945 !! into the Lua context.
Show on old repository browser