How to execute an untrusted Lua file in its own environment from the C API

前端 未结 3 830
花落未央
花落未央 2021-02-06 10:48

I want to execute an untrusted .lua file in its own environment by calling lua_setfenv() so that it cannot affect any of my code.

The documentation for that function tho

3条回答
  •  悲&欢浪女
    2021-02-06 11:41

    luaL_loadfile() will load the chunk, then call lua_setfenv() to set the environment table, then call lua_pcall() to execute the chunk. See recent answer given by Judge Maygarden at Calling lua functions from .lua's using handles?

提交回复
热议问题