<tfoot id='rYOGF'></tfoot>
        <bdo id='rYOGF'></bdo><ul id='rYOGF'></ul>
      <i id='rYOGF'><tr id='rYOGF'><dt id='rYOGF'><q id='rYOGF'><span id='rYOGF'><b id='rYOGF'><form id='rYOGF'><ins id='rYOGF'></ins><ul id='rYOGF'></ul><sub id='rYOGF'></sub></form><legend id='rYOGF'></legend><bdo id='rYOGF'><pre id='rYOGF'><center id='rYOGF'></center></pre></bdo></b><th id='rYOGF'></th></span></q></dt></tr></i><div id='rYOGF'><tfoot id='rYOGF'></tfoot><dl id='rYOGF'><fieldset id='rYOGF'></fieldset></dl></div>

    1. <small id='rYOGF'></small><noframes id='rYOGF'>

      <legend id='rYOGF'><style id='rYOGF'><dir id='rYOGF'><q id='rYOGF'></q></dir></style></legend>

        如何干净地结束 Lua 线程?

        How can I end a Lua thread cleanly?(如何干净地结束 Lua 线程?)
      1. <i id='aGcio'><tr id='aGcio'><dt id='aGcio'><q id='aGcio'><span id='aGcio'><b id='aGcio'><form id='aGcio'><ins id='aGcio'></ins><ul id='aGcio'></ul><sub id='aGcio'></sub></form><legend id='aGcio'></legend><bdo id='aGcio'><pre id='aGcio'><center id='aGcio'></center></pre></bdo></b><th id='aGcio'></th></span></q></dt></tr></i><div id='aGcio'><tfoot id='aGcio'></tfoot><dl id='aGcio'><fieldset id='aGcio'></fieldset></dl></div>
          <tbody id='aGcio'></tbody>
      2. <tfoot id='aGcio'></tfoot>

            <legend id='aGcio'><style id='aGcio'><dir id='aGcio'><q id='aGcio'></q></dir></style></legend>

            <small id='aGcio'></small><noframes id='aGcio'>

                • <bdo id='aGcio'></bdo><ul id='aGcio'></ul>
                  本文介绍了如何干净地结束 Lua 线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的情况是我使用 Lua (C) API 来执行保存在字符串中的脚本.我希望用户能够终止脚本的执行(如果脚本包含无限循环,这是必不可少的),我该怎么做?

                  My situation is that I'm using the Lua (C) API to execute a script held in a string. I would like the user to be able to terminate the execution of the script (this is essential if the script contains an infinite loop), how can I do this?

                  lua_State *Lua = lua_open();
                  char * code;
                  // Initialisation code
                  luaL_dostring(L, code);
                  

                  推荐答案

                  你可以使用钩子在每次 lua 执行一行脚本时回调到 C.在这个钩子函数中,你可以检查用户是否想退出,如果他们想退出就调用 lua_error.

                  You can use a hook to callback to C every time lua executes a line of the script. In this hook function you can check if the user wanted to quit, and call lua_error if they did.

                  static bool ms_quit = false;
                  
                  void IWantToQuit()
                  {
                      ms_quit = true;
                  }
                  
                  void LineHookFunc(lua_State *L, lua_Debug *ar)
                  {
                      if(ar.event == LUA_HOOKLINE)
                          if(ms_quit == true)
                              luaL_error(L, "Too Many Lines Error");
                  }
                  //...
                  
                  lua_State *Lua = lua_open();
                  char * code;
                  // Initialisation code
                  lua_sethook(Lua, &LineHookFunc, LUA_MASKLINE, 0);
                  luaL_dostring(L, code);
                  

                  这篇关于如何干净地结束 Lua 线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Constructor initialization Vs assignment(构造函数初始化 Vs 赋值)
                  Is a `=default` move constructor equivalent to a member-wise move constructor?(`=default` 移动构造函数是否等同于成员移动构造函数?)
                  Has the new C++11 member initialization feature at declaration made initialization lists obsolete?(声明时新的 C++11 成员初始化功能是否使初始化列表过时了?)
                  Order of constructor call in virtual inheritance(虚继承中构造函数调用的顺序)
                  How to use sfinae for selecting constructors?(如何使用 sfinae 选择构造函数?)
                  Initializing a union with a non-trivial constructor(使用非平凡的构造函数初始化联合)
                    <bdo id='hu6Jc'></bdo><ul id='hu6Jc'></ul>
                    <tfoot id='hu6Jc'></tfoot>
                  • <i id='hu6Jc'><tr id='hu6Jc'><dt id='hu6Jc'><q id='hu6Jc'><span id='hu6Jc'><b id='hu6Jc'><form id='hu6Jc'><ins id='hu6Jc'></ins><ul id='hu6Jc'></ul><sub id='hu6Jc'></sub></form><legend id='hu6Jc'></legend><bdo id='hu6Jc'><pre id='hu6Jc'><center id='hu6Jc'></center></pre></bdo></b><th id='hu6Jc'></th></span></q></dt></tr></i><div id='hu6Jc'><tfoot id='hu6Jc'></tfoot><dl id='hu6Jc'><fieldset id='hu6Jc'></fieldset></dl></div>

                          <tbody id='hu6Jc'></tbody>

                        <legend id='hu6Jc'><style id='hu6Jc'><dir id='hu6Jc'><q id='hu6Jc'></q></dir></style></legend>

                        <small id='hu6Jc'></small><noframes id='hu6Jc'>