Old 06-14-2018, 08:50 AM   #1
deeb
Human being with feelings
 
deeb's Avatar
 
Join Date: Feb 2017
Posts: 4,820
Default mysql or nosql with lua. How to require ?

i am curious to see the performance of relational databases inside lua in reaper.
but I don't see any information regarding how to require this kind of libs inside lua from reaper.

Any tips what could be the best way to achieve this?

i will try install : luarocks install --server=http://luarocks.org/dev luasql-sqlite

and will see if i can then require using some method from this thread: https://forum.cockos.com/showthread.php?t=190342

Thank you!
deeb is offline   Reply With Quote
Old 06-14-2018, 09:05 AM   #2
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

As long as it's just Lua and not a .dll library or something, the normal require/loadfile functions will work fine.

Obviously you'd have to provide the library along with your script when you release it, or compile it in. Make sure you check the library's licensing for whether that's okay.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate

Last edited by Lokasenna; 06-14-2018 at 09:59 AM.
Lokasenna is offline   Reply With Quote
Old 06-15-2018, 07:32 AM   #3
deeb
Human being with feelings
 
deeb's Avatar
 
Join Date: Feb 2017
Posts: 4,820
Default

ok lokasenna! thank you : ) i had problems to just install luasql-sqlite. As i had 1 year ago : ) i'll have to spend more time into it.
deeb is offline   Reply With Quote
Old 06-15-2018, 07:59 AM   #4
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

I'm looking at it, and LuaSQL-SQLite is definitely C-based - you won't be able to use it in Reaper.

To clarify a little more, only things that are written completely in Lua will work - if it needs binary libraries, such as this, you're out of luck.

You could work around it by saving variables to a text file, calling a standalone Lua script with LuaRocks and LuaSQL installed, having that script read the text file and then save its output, and then having your Reaper script watch the text file for the output, but... that's really complicated, and end-users will never want to do all of that.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 06-15-2018, 08:14 AM   #5
deeb
Human being with feelings
 
deeb's Avatar
 
Join Date: Feb 2017
Posts: 4,820
Default

i think could call direcly thrue command line, but is a lot of work.
I will look at serialization alternatives
deeb is offline   Reply With Quote
Old 06-15-2018, 08:24 AM   #6
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

How much data do you have to serialize? I use this for saving Radial Menu's menus and settings - it outputs the table as a Lua table, so reloading it just requires loading and executing the file.

Code:
--[[
	Adapted from a post on Stack Overflow:http://stackoverflow.com/questions/6075262/lua-table-tostringtablename-and-table-fromstringstringtable-functions

	- Changed ' ' indents to a full tab
	- Table indices are given []s and ""s where appropriate; Lua was
	  refusing to read the output as a table without them
	- Combined type calls for Number and Boolean since they can both use tostring()

]]--
local function serializeTable(val, name, skipnewlines, depth)
    skipnewlines = skipnewlines or false
    depth = depth or 0

    local tmp = string.rep("\t", depth)

	if name then 
		tmp = tmp .. "[" .. 
		((type(name) == "string") and ('"'..name..'"') or name)
		.. "] = " 
	end

    if type(val) == "table" then
        tmp = tmp .. "{" .. (not skipnewlines and "\n" or "")

        for k, v in GUI.kpairs(val, "full") do
            tmp =  tmp .. serializeTable(v, k, skipnewlines, depth + 1) .. "," .. (not skipnewlines and "\n" or "")
        end

        tmp = tmp .. string.rep("\t", depth) .. "}"
    elseif type(val) == "number" or type(val) == "boolean" then
        tmp = tmp .. tostring(val)
    elseif type(val) == "string" then
        tmp = tmp .. string.format("%q", val)
    else
        tmp = tmp .. "\"[unserializeable datatype:" .. type(val) .. "]\""
    end

    return tmp
end
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 06-15-2018, 08:40 AM   #7
deeb
Human being with feelings
 
deeb's Avatar
 
Join Date: Feb 2017
Posts: 4,820
Default

Cool! i would like to serialize like blobs
deeb is offline   Reply With Quote
Old 06-15-2018, 09:02 AM   #8
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

The only blob library I can find as pure Lua is: https://github.com/25A0/blob
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 06-15-2018, 09:18 AM   #9
deeb
Human being with feelings
 
deeb's Avatar
 
Join Date: Feb 2017
Posts: 4,820
Default

thanks for letting me know!
deeb is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:06 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.