July 17, 2014 LuaD: How to load modules | ||||
---|---|---|---|---|
| ||||
I'm using / testing LuaD atm. It works very well, however, I've encountered a problem. When I load the module lualsp (for "lua server pages") the app crashes. If I run the lua script on its own $ lua5.1 test.lua it works perfectly fine. The lua server page is executed correctly. If I run the same script from within LuaD, the app crashes, same goes for lua.doString("require \"lualsp\""); I haven't been able to figure out how to load the module into lua correctly, obviously there is something going wrong. I hope there is a way. The script test.lua: -- test.lua require "lualsp" -- function from lualsp module written in C++ dofile_lsp("../examples/example1.html") -- end test.lua The lsp file: <html> <body> <? name = "Chris"?> <? print(name) ?> </body> </html> |
July 17, 2014 Re: LuaD: How to load modules | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris | On Thursday, 17 July 2014 at 10:53:56 UTC, Chris wrote: > I'm using / testing LuaD atm. It works very well, however, I've encountered a problem. When I load the module lualsp (for "lua server pages") the app crashes. If I run the lua script on its own > > $ lua5.1 test.lua > > it works perfectly fine. The lua server page is executed correctly. If I run the same script from within LuaD, the app crashes, same goes for > > lua.doString("require \"lualsp\""); > > I haven't been able to figure out how to load the module into lua correctly, obviously there is something going wrong. I hope there is a way. > > The script test.lua: > > -- test.lua > require "lualsp" > > -- function from lualsp module written in C++ > dofile_lsp("../examples/example1.html") > -- end test.lua > > The lsp file: > > <html> > <body> > > <? name = "Chris"?> > > <? print(name) ?> > > </body> > </html> What works is when I compile lualsp into a static library and then link my program against it. Then I can do: lua_State* L = luaL_newstate(); auto lua = new LuaState(L); lua.openLibs(); int lib = luaopen_lualsp(L); // defined in llsplib.cpp (i.e. the module) if (lib == 0) { auto lsp = lua.get!LuaFunction("dofile_lsp"); lua.doString("dofile_lsp('path/to/example1.html')"); } But I want to be able to load an external library dynamically. |
Copyright © 1999-2021 by the D Language Foundation