Lua API unload luaL_loadfile












1















I working on Lua scripter in game that users are able to write custom Lua script and load it.



I already done with implementation and functions



L = luaL_newstate()
luaL_openlibs()
lua_register(L, cFunction, "luaFunction")
lua_register(L, cFunction2, "luaFunction2")
lua_register(L, cFunctionN, "luaFunctionN")


What I trying now?
Possibility to execute/kill script on button press, below picture for more clarity : https://i.stack.imgur.com/eJQzg.png



All scripts from scripter need to access to Lib.lua so i do:



luaL_loadfile(L, "Lib.lua")
lua_pcall(L, 0, 0, 0)


Then to load script i could use this same thing and is ok until user want to kill/unload script.



luaL_loadfile(L, "script.lua")
lua_pcall(L, 0, 0, 0)


I digging in many threads about Lua API and currently no good answer for this problem.



Ppls talking about lua_newthread that i already tried to implement but no success.



T = lua_newthread(L)
luaL_loadfile(L, "script.lua")
lua_pcall(L, 0, 0, 0)
Return >> Attempt to call a nill value. Look like new thread has no access to Lib.lua


Also there is other problem, when i register function i use:



lua_register(L, cFunction, "luaFunction")


Then even i able to create a thread functions from luaL_newstate*L required to pass handle L to working while handle of thread is T.



Example of C function passing to lua:



 static int add (lua_State *L) {
double a = lua_tonumber(L, -1); /* get argument 1 */
double b = lua_tonumber(L, -2); /* get argument 2 */
lua_pushnumber(L, a+b); /* push result */
return 1; /* number of results */
}


Any king of is appreciated.



Regards,
Ascer










share|improve this question























  • nvm solved it out :) I created a single luaL_state for each script and register all functions then create an array for keep all registry. To close just use lua_close(scriptHandle)

    – Ascer
    Nov 23 '18 at 10:15


















1















I working on Lua scripter in game that users are able to write custom Lua script and load it.



I already done with implementation and functions



L = luaL_newstate()
luaL_openlibs()
lua_register(L, cFunction, "luaFunction")
lua_register(L, cFunction2, "luaFunction2")
lua_register(L, cFunctionN, "luaFunctionN")


What I trying now?
Possibility to execute/kill script on button press, below picture for more clarity : https://i.stack.imgur.com/eJQzg.png



All scripts from scripter need to access to Lib.lua so i do:



luaL_loadfile(L, "Lib.lua")
lua_pcall(L, 0, 0, 0)


Then to load script i could use this same thing and is ok until user want to kill/unload script.



luaL_loadfile(L, "script.lua")
lua_pcall(L, 0, 0, 0)


I digging in many threads about Lua API and currently no good answer for this problem.



Ppls talking about lua_newthread that i already tried to implement but no success.



T = lua_newthread(L)
luaL_loadfile(L, "script.lua")
lua_pcall(L, 0, 0, 0)
Return >> Attempt to call a nill value. Look like new thread has no access to Lib.lua


Also there is other problem, when i register function i use:



lua_register(L, cFunction, "luaFunction")


Then even i able to create a thread functions from luaL_newstate*L required to pass handle L to working while handle of thread is T.



Example of C function passing to lua:



 static int add (lua_State *L) {
double a = lua_tonumber(L, -1); /* get argument 1 */
double b = lua_tonumber(L, -2); /* get argument 2 */
lua_pushnumber(L, a+b); /* push result */
return 1; /* number of results */
}


Any king of is appreciated.



Regards,
Ascer










share|improve this question























  • nvm solved it out :) I created a single luaL_state for each script and register all functions then create an array for keep all registry. To close just use lua_close(scriptHandle)

    – Ascer
    Nov 23 '18 at 10:15
















1












1








1








I working on Lua scripter in game that users are able to write custom Lua script and load it.



I already done with implementation and functions



L = luaL_newstate()
luaL_openlibs()
lua_register(L, cFunction, "luaFunction")
lua_register(L, cFunction2, "luaFunction2")
lua_register(L, cFunctionN, "luaFunctionN")


What I trying now?
Possibility to execute/kill script on button press, below picture for more clarity : https://i.stack.imgur.com/eJQzg.png



All scripts from scripter need to access to Lib.lua so i do:



luaL_loadfile(L, "Lib.lua")
lua_pcall(L, 0, 0, 0)


Then to load script i could use this same thing and is ok until user want to kill/unload script.



luaL_loadfile(L, "script.lua")
lua_pcall(L, 0, 0, 0)


I digging in many threads about Lua API and currently no good answer for this problem.



Ppls talking about lua_newthread that i already tried to implement but no success.



T = lua_newthread(L)
luaL_loadfile(L, "script.lua")
lua_pcall(L, 0, 0, 0)
Return >> Attempt to call a nill value. Look like new thread has no access to Lib.lua


Also there is other problem, when i register function i use:



lua_register(L, cFunction, "luaFunction")


Then even i able to create a thread functions from luaL_newstate*L required to pass handle L to working while handle of thread is T.



Example of C function passing to lua:



 static int add (lua_State *L) {
double a = lua_tonumber(L, -1); /* get argument 1 */
double b = lua_tonumber(L, -2); /* get argument 2 */
lua_pushnumber(L, a+b); /* push result */
return 1; /* number of results */
}


Any king of is appreciated.



Regards,
Ascer










share|improve this question














I working on Lua scripter in game that users are able to write custom Lua script and load it.



I already done with implementation and functions



L = luaL_newstate()
luaL_openlibs()
lua_register(L, cFunction, "luaFunction")
lua_register(L, cFunction2, "luaFunction2")
lua_register(L, cFunctionN, "luaFunctionN")


What I trying now?
Possibility to execute/kill script on button press, below picture for more clarity : https://i.stack.imgur.com/eJQzg.png



All scripts from scripter need to access to Lib.lua so i do:



luaL_loadfile(L, "Lib.lua")
lua_pcall(L, 0, 0, 0)


Then to load script i could use this same thing and is ok until user want to kill/unload script.



luaL_loadfile(L, "script.lua")
lua_pcall(L, 0, 0, 0)


I digging in many threads about Lua API and currently no good answer for this problem.



Ppls talking about lua_newthread that i already tried to implement but no success.



T = lua_newthread(L)
luaL_loadfile(L, "script.lua")
lua_pcall(L, 0, 0, 0)
Return >> Attempt to call a nill value. Look like new thread has no access to Lib.lua


Also there is other problem, when i register function i use:



lua_register(L, cFunction, "luaFunction")


Then even i able to create a thread functions from luaL_newstate*L required to pass handle L to working while handle of thread is T.



Example of C function passing to lua:



 static int add (lua_State *L) {
double a = lua_tonumber(L, -1); /* get argument 1 */
double b = lua_tonumber(L, -2); /* get argument 2 */
lua_pushnumber(L, a+b); /* push result */
return 1; /* number of results */
}


Any king of is appreciated.



Regards,
Ascer







api lua






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 8:06









AscerAscer

61




61













  • nvm solved it out :) I created a single luaL_state for each script and register all functions then create an array for keep all registry. To close just use lua_close(scriptHandle)

    – Ascer
    Nov 23 '18 at 10:15





















  • nvm solved it out :) I created a single luaL_state for each script and register all functions then create an array for keep all registry. To close just use lua_close(scriptHandle)

    – Ascer
    Nov 23 '18 at 10:15



















nvm solved it out :) I created a single luaL_state for each script and register all functions then create an array for keep all registry. To close just use lua_close(scriptHandle)

– Ascer
Nov 23 '18 at 10:15







nvm solved it out :) I created a single luaL_state for each script and register all functions then create an array for keep all registry. To close just use lua_close(scriptHandle)

– Ascer
Nov 23 '18 at 10:15














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53442760%2flua-api-unload-lual-loadfile%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53442760%2flua-api-unload-lual-loadfile%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen