在C++中为LUA添加PATH路径(搜索路径)

来源:互联网 发布:网络教育课程是啥子 编辑:程序博客网 时间:2024/06/08 20:00
[cpp] view plain copy
  1. void LuaAddPath(lua_State *ls, char *name, char *value) {  
  2.     string v;  
  3.   
  4.     lua_getglobal(ls, "package");  
  5.     lua_getfield(ls, -1, name);  
  6.     v.append(lua_tostring(ls, -1));  
  7.     v.append(";");  
  8.     v.append(value);  
  9.     lua_pushstring(ls, v.c_str());  
  10.     lua_setfield(ls, -3, name);  
  11.     lua_pop(ls, 2);  
  12. }  


[cpp] view plain copy
  1. LuaAddPath(m_ls->GetCState(), "path"".\\lual\\?.lua");  
  2. LuaAddPath(m_ls->GetCState(), "cpath"".\\lual\\?.dll");  
原创粉丝点击