lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

there are various examples, but I maybe I can not see
the trees because the forest is in the way...

>From C++ I want to repeatedly load the same Lua code
string and receive the result, but each time with
other global variable values. 

In Pseudocode:

lua_State st = luaL_newstate();
char* code = "return isPrime(n)";
for(int n=2; n<N; ++n)) {
  lua_pushstring(st, tostring(n) );
  lua_setglobal(st, "n");
  luaL_loadstring(st, code); /* HERE */
  cerr << n 
    << (lua_tointeger(st, 1) ? " is" : " is not" ) 
    << " prime." << endl;
}


It seems to me that /* HERE */ may be unnecessary
inside the loop, since it is always the same string.
But how to _execute_ a piece of code without _loading_
it? 
Any hints? Is there something like an 'prepare SQL
statement' mechanism??

Thanks in advance.

tschau, towi.



      __________________________________________________________
Sent from Yahoo! Mail.
A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html