How do you use lua libraries?

User avatar
false_chicken
Member
 
Posts: 51
Joined: Wed Feb 04, 2015 23:41
Location: Florida, USA
GitHub: falsechicken
In-game: false_chicken

How do you use lua libraries?

by false_chicken » Thu Feb 12, 2015 20:33

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:

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.
DISCLAIMER: I am probably wrong.
 

User avatar
rubenwardy
Moderator
 
Posts: 5796
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: How do you use lua libraries?

by rubenwardy » Thu Feb 12, 2015 20:34

use dofile with minetest.get_modpath. See init.lua of default game.
 

User avatar
false_chicken
Member
 
Posts: 51
Joined: Wed Feb 04, 2015 23:41
Location: Florida, USA
GitHub: falsechicken
In-game: false_chicken

Re: How do you use lua libraries?

by false_chicken » Thu Feb 12, 2015 20:36

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.
DISCLAIMER: I am probably wrong.
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 4 guests