Page 1 of 1

How do you use lua libraries?

PostPosted: Thu Feb 12, 2015 20:33
by false_chicken
I have created a custom library consisting of only helper functions. I have tried to 'include' the file using 'require "libname" ' but I get the error below:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
10:53:00: ERROR[main]: ...jects/Repos/minetest/bin/../mods/modname/init.lua:35: module 'libname' not found:
10:53:00: ERROR[main]:    no field package.preload['libname']
10:53:00: ERROR[main]:    no file './libname.lua'
10:53:00: ERROR[main]:    no file '/usr/local/share/lua/5.1/libname.lua'
10:53:00: ERROR[main]:    no file '/usr/local/share/lua/5.1/libname/init.lua'
10:53:00: ERROR[main]:    no file '/usr/local/lib/lua/5.1/libname.lua'
10:53:00: ERROR[main]:    no file '/usr/local/lib/lua/5.1/libname/init.lua'
10:53:00: ERROR[main]:    no file '/home/user/ownCloud/Projects/Repos/minetest/bin/../mods/modname.lua'
10:53:00: ERROR[main]:    no file './libname.so'
10:53:00: ERROR[main]:    no file '/usr/local/lib/lua/5.1/libname.so'
10:53:00: ERROR[main]:    no file '/usr/local/lib/lua/5.1/libname.so'


The library is located in the same directory as the init.lua of the mod. It seems like it is not looking in the mod's directory. Any suggestions? Thanks.

Re: How do you use lua libraries?

PostPosted: Thu Feb 12, 2015 20:34
by rubenwardy
use dofile with minetest.get_modpath. See init.lua of default game.

Re: How do you use lua libraries?

PostPosted: Thu Feb 12, 2015 20:36
by false_chicken
Ah. Thank you. I was thinking dofile was more like actually executing it like a script. Not like 'including' the file as in other languages.