|
Npc * getNpc(lua_State *luaVm); But yea, I don't know what the differences are (other than getting values from the top with negative values)... > Date: Sun, 30 May 2010 12:33:42 +0200 > From: thomas@duboucher.eu > To: lua@bazar2.conectiva.com.br > Subject: Re: Lua and C++ (stack) > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Le 30/05/2010 12:11, Erwin Oegema a écrit : > > > > Hello, > > > > I was wondering why my application doesn't get the correct values from the stack with this function under a Release build (it does work under Debug ...): > > > > int LuaExports::askNumber(lua_State *luaVm) { > > getNpc(luaVm)->sendGetNumber(lua_tointeger(luaVm, -3), lua_tointeger(luaVm, -2), lua_tointeger(luaVm, -1)); > > return lua_yield(luaVm, 1); > > } > > > > O.o... Sometimes the values are switched too... > > Using the following code works perfectly: > > > > int LuaExports::askNumber(lua_State *luaVm) { > > > > getNpc(luaVm)->sendGetNumber(lua_tointeger(luaVm, 1), > > lua_tointeger(luaVm, 2), lua_tointeger(luaVm, 3)); > > > > return lua_yield(luaVm, 1); > > > > } > > > > > > So I want to know what the correct (best?) way is to get a value from the stack? > > > > Thanks in advance. > > > > Are you sure you understand the differences between positive and > negative indexes for the stack? As for me, I prefer using negative > indexes (my teachers told me to always access stack from the top). > Also, for the differences between debug and release, I suspect that > some aggressive optimization may change the order in which functions are > called. I suppose that getNpc returns some kind of object or structure; > I had problems like this with this kind of code when the compiler has no > clues of how to optimize. > > Thomas. > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.10 (MingW32) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ > > iEYEARECAAYFAkwCPwYACgkQBV7eXqefhqhUvgCfQ6hYNReZOYi0gYz99jFKgZxl > HMAAniT89Q3AJlgU5lkqbroHjBCGIl6V > =8Q/k > -----END PGP SIGNATURE----- Tijd voor een nieuwe telefoon? Bekijk de mogelijkheden van een Windows Phone! |