Fluorohydride / ygopro-core

ygopro script engine.
MIT License
327 stars 134 forks source link

Open lua library #501

Closed salix5 closed 1 year ago

salix5 commented 1 year ago

Problem

https://www.lua.org/manual/5.4/manual.html#6

Alternatively, the host program can open them individually by using luaL_requiref to call luaopen_base (for the basic library), luaopen_package (for the package library), luaopen_coroutine (for the coroutine library), luaopen_string (for the string library), luaopen_utf8 (for the UTF-8 library), luaopen_table (for the table library), luaopen_math (for the mathematical library), luaopen_io (for the I/O library), luaopen_os (for the operating system library), and luaopen_debug (for the debug library). These functions are declared in lualib.h.

https://www.lua.org/manual/5.4/manual.html#luaL_requiref void luaL_requiref (lua_State L, const char modname, lua_CFunction openf, int glb);

If package.loaded[modname] is not true, calls the function openf with the string modname as an argument and sets the call result to package.loaded[modname], as if that function has been called through require.

If glb is true, also stores the module into the global modname.

Leaves a copy of the module on the stack.

If we do not want to use libraries like io, os, we can open necessary libraries.

Solution

Now it use luaL_requiref() to open necessary libraries.

salix5 commented 1 year ago

@mercury233 Can we merge this one?