MCPcopy Create free account
hub / github.com/crownengine/crown / addreturn

Function addreturn

src/lua/lua_environment.cpp:146–156  ·  view source on GitHub ↗

** Try to compile line on the stack as 'return ;'; on return, stack ** has either compiled chunk or original line (if compilation failed). */

Source from the content-addressed store, hash-verified

144** has either compiled chunk or original line (if compilation failed).
145*/
146static int addreturn(lua_State *L)
147{
148 const char *line = lua_tostring(L, -1); /* original line */
149 const char *retline = lua_pushfstring(L, "return %s;", line);
150 int status = luaL_loadbuffer(L, retline, strlen(retline), "=stdin");
151 if (status == LUA_OK)
152 lua_remove(L, -2); /* remove modified line */
153 else
154 lua_pop(L, 2); /* pop result from 'luaL_loadbuffer' and modified line */
155 return status;
156}
157
158/*
159** Read a line and try to load (compile) it first as an expression (by

Callers 1

loadlineFunction · 0.85

Calls 4

strlenFunction · 0.85
lua_pushfstringFunction · 0.50
luaL_loadbufferFunction · 0.50
lua_removeFunction · 0.50

Tested by

no test coverage detected