MCPcopy Create free account
hub / github.com/Tencent/UnLua / LoadChunk

Function LoadChunk

Plugins/UnLua/Source/UnLua/Private/UnLuaBase.cpp:95–123  ·  view source on GitHub ↗

* Load a Lua chunk without running it */

Source from the content-addressed store, hash-verified

93 * Load a Lua chunk without running it
94 */
95 bool LoadChunk(lua_State *L, const char *Chunk, int32 ChunkSize, const char *ChunkName, const char *Mode, int32 Env)
96 {
97 int32 Code = luaL_loadbufferx(L, Chunk, ChunkSize, ChunkName, Mode); // loads the buffer as a Lua chunk
98 if (Code != LUA_OK)
99 {
100 UE_LOG(LogUnLua, Warning, TEXT("Failed to call luaL_loadbufferx, error code: %d"), Code);
101 ReportLuaCallError(L); // report pcall error
102 }
103
104 if (Code == LUA_OK)
105 {
106 if (Env != 0)
107 {
108 /* 'env' parameter? */
109 lua_pushvalue(L, Env); /* environment for loaded function */
110 if (!lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */
111 {
112 lua_pop(L, 1); /* remove 'env' if not used by previous call */
113 }
114 }
115 }
116 else
117 {
118 lua_pushnil(L); /* error (message is on top of the stack) */
119 lua_insert(L, -2); /* put before error message */
120 }
121
122 return Code == LUA_OK;
123 }
124
125 /**
126 * Run a Lua chunk

Callers 1

LoadFileFunction · 0.85

Calls 5

luaL_loadbufferxFunction · 0.85
ReportLuaCallErrorFunction · 0.85
lua_pushvalueFunction · 0.85
lua_setupvalueFunction · 0.85
lua_pushnilFunction · 0.85

Tested by

no test coverage detected