!> lua API module lua_api_m use easy_lua_m, only: get_value use error_stop_m, only: error_stop use kinds_m, only: rp use lua use stdlib_logger, only: stdlog => global_logger use types_m, only: region_t use, intrinsic :: iso_c_binding, only: c_ptr use easy_string_m, only: to_string implicit none public :: lua_input contains !> 读取 lua 脚本 subroutine lua_input(lua_script, region) character(*), intent(in) :: lua_script type(region_t), intent(out) :: region type(c_ptr) :: lua_state integer :: status lua_state = lual_newstate() call lual_openlibs(lua_state) status = lual_loadfile(lua_state, lua_script) if (status /= 0) then call error_stop('Error loading script: '//lua_script, & 'lua_api_m%lua_input') end if status = lua_pcall(lua_state, 0, 0, 0) if (status /= 0) then call error_stop('Error running script: '//lua_script, & 'lua_api_m%lua_input') end if status = lua_getglobal(lua_state, 'region') ! if (status /= 0) then ! call error_stop('Error getting region from script: '//lua_script, & ! 'lua_api_m%lua_input') ! end if status = lua_pcall(lua_state, 0, 10, 0) if (status /= 0) then call error_stop('Error running script: '//lua_script, & 'lua_api_m%lua_input') end if call get_value(lua_state, region%loc, index=-10) call get_value(lua_state, region%vel, index=-9) call get_value(lua_state, region%mass, index=-8) call get_value(lua_state, region%rho, index=-7) call get_value(lua_state, region%p, index=-6) call get_value(lua_state, region%u, index=-5) call get_value(lua_state, region%itype, index=-4) call get_value(lua_state, region%hsml, index=-3) call get_value(lua_state, region%n, index=-2) call get_value(lua_state, region%m, index=-1) call lua_close(lua_state) call stdlog%log_information('Loaded region from script: '//lua_script) call stdlog%log_information('Region:') call stdlog%log_information(' n = '//to_string(region%n)) call stdlog%log_information(' m = '//to_string(region%m)) call stdlog%log_information(' hsml = '//to_string(region%hsml)) end subroutine lua_input end module lua_api_m