| 276 | } |
| 277 | |
| 278 | void init_lua_io(lua_State* L) { |
| 279 | |
| 280 | geo_cite_with_info( |
| 281 | "WEB:lua", |
| 282 | "GEOGRAM has an embedded LUA interpreter " |
| 283 | "(LUA is worth one thousand times the few kilobytes it uses !)." |
| 284 | ); |
| 285 | |
| 286 | lua_newtable(L); |
| 287 | |
| 288 | lua_bindwrapper(L, FileSystem::is_file); |
| 289 | lua_bindwrapper(L, FileSystem::is_directory); |
| 290 | lua_bindwrapper(L, FileSystem::create_directory); |
| 291 | lua_bindwrapper(L, FileSystem::delete_directory); |
| 292 | lua_bindwrapper(L, FileSystem::delete_file); |
| 293 | lua_bindwrapper(L, FileSystem::get_current_working_directory); |
| 294 | lua_bindwrapper(L, FileSystem::set_current_working_directory); |
| 295 | lua_bindwrapper(L, FileSystem::rename_file); |
| 296 | lua_bindwrapper(L, FileSystem::get_time_stamp); |
| 297 | lua_bindwrapper(L, FileSystem::extension); |
| 298 | lua_bindwrapper(L, FileSystem::base_name); |
| 299 | lua_bindwrapper(L, FileSystem::dir_name); |
| 300 | lua_bindwrapper(L, FileSystem::copy_file); |
| 301 | lua_bindwrapper(L, FileSystem::set_executable_flag); |
| 302 | lua_bindwrapper(L, FileSystem::touch); |
| 303 | lua_bindwrapper(L, FileSystem::normalized_path); |
| 304 | lua_bindwrapper(L, FileSystem::home_directory); |
| 305 | lua_bindwrapper(L, FileSystem::documents_directory); |
| 306 | |
| 307 | lua_bindwrapper(L, LUAFileSystemImpl::get_directory_entries); |
| 308 | lua_bindwrapper(L, LUAFileSystemImpl::get_files); |
| 309 | lua_bindwrapper(L, LUAFileSystemImpl::get_subdirectories); |
| 310 | |
| 311 | lua_bindwrapper(L, LUAFileSystemImpl::os_name); |
| 312 | |
| 313 | lua_setglobal(L, "FileSystem"); |
| 314 | |
| 315 | // Save a copy of LUA's built-in "require" |
| 316 | // and "print" functions in the "GEO" table declared to |
| 317 | // the registry. |
| 318 | lua_newtable(L); |
| 319 | lua_getglobal(L, "require"); |
| 320 | lua_setfield(L, -2, "lua_require_func"); |
| 321 | lua_getglobal(L, "print"); |
| 322 | lua_setfield(L, -2, "lua_print_func"); |
| 323 | lua_getglobal(L, "tostring"); |
| 324 | lua_setfield(L, -2, "lua_tostring_func"); |
| 325 | lua_setfield(L, LUA_REGISTRYINDEX, "GEO"); |
| 326 | |
| 327 | // Replace require(),print() and tostring() with our own versions. |
| 328 | lua_bindwrapperglobal(L, require); |
| 329 | lua_bindwrapperglobal(L, print); |
| 330 | lua_bindwrapperglobal(L, tostring); |
| 331 | } |
| 332 | |
| 333 | /************************************************************************/ |
| 334 |
no outgoing calls
no test coverage detected