[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: problem with calling lua5 from c++
- From: Peter Shook <pshook@...>
- Date: Mon, 05 May 2003 15:43:49 -0400
To get the number on top of the stack, you should use -1 for the index.
In Lua 5.0, lua_baselibopen(L) leaves a table on top of the stack now,
so the result isn't at stack index 1.
- Peter Shook
$ diff -u add.cc fixed.cc
--- add.cc 2003-05-05 15:31:39.000000000 -0400
+++ fixed.cc 2003-05-05 15:31:33.000000000 -0400
@@ -3,6 +3,7 @@
extern "C" {
#include "lua.h"
+ #include "lauxlib.h"
#include "lualib.h"
}
@@ -27,7 +28,7 @@
lua_call(L, 2, 1);
/* get the result */
- sum = (int)lua_tonumber(L, 1);
+ sum = (int)lua_tonumber(L, -1);
lua_pop(L, 1);
return sum;
@@ -38,10 +39,11 @@
int sum;
/* initialize Lua */
- L = lua_open(0);
+ L = lua_open();
/* load Lua base libraries */
lua_baselibopen(L);
+ lua_settop(L, 0);
/* load the script */
lua_dofile(L, "add.lua");