Re: LUA interface giving me trouble with garbage collection patch
On Fri, Jul 11, 2014 at 12:49 AM, Ben Fritz fritzophre...@gmail.com wrote: On Wednesday, July 9, 2014 11:24:50 PM UTC-5, Yukihiro Nakadaira wrote: Here is sample code. [edited] L = luaL_newstate(); lua_pushcclosure(L, add, 0); lua_pushinteger(L, 111); lua_pushinteger(L, 222); lua_call(L, 2 /* nargs */, 1 /* nresults */); r = lua_tointeger(L, -1); lua_pop(L, 1); lua_close(L); Thanks! I'll give this a try later. What's the -1 for in lua_tointeger()? Is there a good way to test this when I'm done? E.g. are there LUA tests in Vim's test suite that will exercise the garbage collector? Or maybe a toy script using the LUA interface I could run myself? I have no idea. -- Yukihiro Nakadaira - yukihiro.nakada...@gmail.com -- -- You received this message from the vim_dev maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups vim_dev group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: LUA interface giving me trouble with garbage collection patch
-BEGIN PGP SIGNED MESSAGE- Hash: SHA512 On July 10, 2014 7:49:02 PM GMT+03:00, Ben Fritz fritzophre...@gmail.com wrote: On Wednesday, July 9, 2014 11:24:50 PM UTC-5, Yukihiro Nakadaira wrote: Here is sample code. [edited] L = luaL_newstate(); lua_pushcclosure(L, add, 0); lua_pushinteger(L, 111); lua_pushinteger(L, 222); lua_call(L, 2 /* nargs */, 1 /* nresults */); r = lua_tointeger(L, -1); lua_pop(L, 1); lua_close(L); Thanks! I'll give this a try later. What's the -1 for in lua_tointeger()? Almost all lua_* functions operate with stack. -1 is stack index. Like indexes in lua itself 1 means first value in the stack, 2 means second, ..., -1 means last, -2 means last but one, ... In lua_pop you though specify how many values to pop, not which element to pop. Is there a good way to test this when I'm done? E.g. are there LUA tests in Vim's test suite that will exercise the garbage collector? Or maybe a toy script using the LUA interface I could run myself? -BEGIN PGP SIGNATURE- Version: APG v1.1.1 iQI1BAEBCgAfBQJTvrb/GBxaeVggPHp5eC52aW1AZ21haWwuY29tPgAKCRCf3UKj HhHSvmnCD/9oKtyxddAIENOS3Yj+18oqxBAfgNFKjNiToD7tY87rx999YYFevnIc KhgHaoiqcyw4cmTLWnBduoA1VmtUGt8iwxT9VXoOpw6HfbWqiuaqAsoIKrLIoLZp H7zcLZIQX763eimUY/PsUgzDVShR73OsjHl8x0PcoYXsh80KcW42Fa5xNoV7O4lr eqnG5V3OsQ6zcOz+SjUN6J3yHITDOpLGe0YNBuSctPqRtHooNR191rzfylQAJna9 5Mx5r05rXAg++HKF6sb7btf0lWMaUmYNJvTweRaxd6mSywxgwh9M+jZ7yiGXE9r3 thD7Be3Tk7woQT0ZdgkoioH6/efZNovoVf2NB/eOU17w3Dxm0doHfyH/s4xH5Dqq 4m2wJMtwlV2R0SYVYjzSOUXBVRxunUlU9m0K4CV2FUUwabLGaEJvmfegUt25sUlL pcO1OFaJNLjGyHM96xbMwv1GpjRgUAfSjVbbDHxjeV/GeanemLlp8etYw1CTP9zs CNNlVMzoHMSvYC8dGO4lqv7fdXNSFzvfUT/lL6i4trxVupgCvZ3oxWX4VUBTHRd4 Zzjr20iVLe4TGJTlSyCScvpMSZGdNiEEBhYhUpZGE20J5On7w5y2XHryrsNn+dOP ZLNVywtzroQxKaLK79aOf4UDJhH2eKTGpuOiKQCnTk7/TxUXlPadTw== =UYLM -END PGP SIGNATURE- -- -- You received this message from the vim_dev maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups vim_dev group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: LUA interface giving me trouble with garbage collection patch
On Wednesday, July 9, 2014 11:24:50 PM UTC-5, Yukihiro Nakadaira wrote: Here is sample code. [edited] L = luaL_newstate(); lua_pushcclosure(L, add, 0); lua_pushinteger(L, 111); lua_pushinteger(L, 222); lua_call(L, 2 /* nargs */, 1 /* nresults */); r = lua_tointeger(L, -1); lua_pop(L, 1); lua_close(L); Thanks! I'll give this a try later. What's the -1 for in lua_tointeger()? Is there a good way to test this when I'm done? E.g. are there LUA tests in Vim's test suite that will exercise the garbage collector? Or maybe a toy script using the LUA interface I could run myself? -- -- You received this message from the vim_dev maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups vim_dev group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: LUA interface giving me trouble with garbage collection patch
On Mon, Jul 7, 2014 at 2:36 PM, Benjamin Fritz fritzophre...@gmail.com wrote: I want to finish up this patch to fix a crash in Vim: https://groups.google.com/d/topic/vim_dev/dnN58kO5Vg4/discussion I changed luaV_setref() to return a value if garbage collection cannot safely proceed. But, I do not know how to get that return value back to the code calling it from eval.c, via set_ref_in_lua(). Can someone please explain briefly how the function calls in the LUA interface work? I cannot figure out how to get a return value back from lua_call(), in the C code. Here is sample code. #include lua.h #include lauxlib.h #include stdio.h /* int add(int x, int y) */ int add(lua_State *L) { int x = lua_tointeger(L, 1); int y = lua_tointeger(L, 2); /* push result to stack */ lua_pushinteger(L, x + y); /* return number of results */ return 1; } int main() { lua_State *L; int r; L = luaL_newstate(); /* r = add(111, 222) */ lua_pushcclosure(L, add, 0); lua_pushinteger(L, 111); lua_pushinteger(L, 222); lua_call(L, 2 /* nargs */, 1 /* nresults */); /* get results */ r = lua_tointeger(L, -1); /* remove results from stack */ lua_pop(L, 1); printf(add(111, 222) = %d\n, r); lua_close(L); return 0; } -- Yukihiro Nakadaira - yukihiro.nakada...@gmail.com -- -- You received this message from the vim_dev maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups vim_dev group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
LUA interface giving me trouble with garbage collection patch
I want to finish up this patch to fix a crash in Vim: https://groups.google.com/d/topic/vim_dev/dnN58kO5Vg4/discussion I changed luaV_setref() to return a value if garbage collection cannot safely proceed. But, I do not know how to get that return value back to the code calling it from eval.c, via set_ref_in_lua(). Can someone please explain briefly how the function calls in the LUA interface work? I cannot figure out how to get a return value back from lua_call(), in the C code. -- -- You received this message from the vim_dev maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups vim_dev group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.