MCPcopy Create free account
hub / github.com/NetHack/NetHack / nhlL_openlibs

Function nhlL_openlibs

src/nhlua.c:2845–2963  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2843
2844#ifdef NHL_SANDBOX
2845staticfn void
2846nhlL_openlibs(lua_State *L, uint32_t lflags)
2847{
2848 /* translate lflags from user-friendly to internal */
2849 if (NHL_SB_DEBUGGING & lflags) {
2850 lflags |= NHL_SB_DB_SAFE;
2851 }
2852 /* only for debugging the sandbox integration */
2853 if (NHL_SB_ALL & lflags) {
2854 lflags = -1;
2855 } else if (NHL_SB_SAFE & lflags) {
2856 lflags |= NHL_SB_BASE_BASE;
2857 lflags |= NHL_SB_COROUTINE;
2858 lflags |= NHL_SB_TABLE;
2859 lflags |= NHL_SB_STRING;
2860 lflags |= NHL_SB_MATH;
2861 lflags |= NHL_SB_UTF8;
2862 } else if (NHL_SB_VERSION) {
2863 lflags |= NHL_SB_BASE_BASE;
2864 }
2865#ifdef notyet
2866/* Handling I/O is complex, so it's not available yet. I'll
2867finish it if and when we need it. (keni)
2868 - hooked open; array of tuples of (r/w/rw/a/etc, directory pat, file pat)
2869
2870{"close", io_close}, but with no args closes default output, so needs hook
2871{"flush", io_flush},
2872{"lines", io_lines}, hook due to filename
2873{"open", io_open}, hooked version:
2874 only safe if mode not present or == "r"
2875 or WRITEIO
2876 only safe if path has no slashes
2877 XXX probably need to be: matches port-specific list of paths
2878 WRITEIO needs a different list
2879 dlb integration?
2880 may need to #define l_getc (but that wouldn't hook core)
2881 may need to #define fopen/fread/fwrite/feof/ftell (etc?)
2882 ugh: lauxlib.c uses getc() below luaL_loadfilex
2883 override in lua.h?
2884 ugh: liolib.c uses getc() below g_read->test_eof
2885 override in lua.h?
2886{"read", io_read},
2887{"type", io_type},
2888{"input", io_input}, safe with a complex hook, but may be needed for read?
2889WRITEIO: needs changes to hooked open?
2890{"output", io_output}, do we want to allow access to default output?
2891 {"write", io_write},
2892UNSAFEIO:
2893 {"popen", io_popen},
2894 {"tmpfile", io_tmpfile},
2895*/
2896#endif
2897
2898 if (lflags & NHL_SB_BASEMASK) {
2899 int baselib;
2900 /* load the entire library ... */
2901 luaL_requiref(L, LUA_GNAME, luaopen_base, 1);
2902

Callers 1

nhl_initFunction · 0.85

Calls 2

hook_openFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected