lua-users home
lua-l archive

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


El Miércoles 26 Febrero 2003 19:50, Luiz Henrique de Figueiredo escribió:
> >I donwloaded and compiled lua 5 beta and tried to test an old small test
> > app, but now i got an error about lua_dostring. What happened with it in
> > version 5? Which is the correct way to execute code from strings/files
> > now?
>
> lua_dostring now exists in lauxlib for compatibility only.
> Try #include'ing auxlib.h and linking with liblualib.a.
>
> lua_dostring has been replaced by the more flexible lua_load. lauxlib
> contains luaL_loadbuffer for convenience. See the implementation
> of lua_dostring in lauxlib.c to see how to use lua_load and
> luaL_loadbuffer. --lhf
So, my app looks this way now (old style, stolen from the tutorial sent some 
time ago):

#include <stdio.h> 
extern "C" {
#include <lua.h>
#include <lualib.h>
 };

int main(int argc, char* argv[ ]) 
{ 
lua_State* luaVM = lua_open(0);

 
if (NULL == luaVM) { printf("Error Initializing lua\n"); return -1; 
}
lua_baselibopen(luaVM); 
lua_iolibopen(luaVM); 
lua_strlibopen(luaVM); 
lua_mathlibopen(luaVM);
 // Do stuff with lua code.
 
  char* strLuaInput = "a = 1 + 1;\n print(a);\n";
  
   lua_dostring(luaVM, strLuaInput);
   
    lua_close(luaVM); 
    
     return 0; 
}
     
What is the correct way now usin lua_load?

-- 
Roger D. Vargas
ICQ: 117641572
Linux user: 180787
* Tanto si piensas que puedes, como si piensas que no puedes, tienes razón *
Henry Ford