Cool VL Viewer forum

View unanswered posts | View active topics It is currently 2017-11-19 12:27:17



Reply to topic  [ 79 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6 ... 8  Next
Lua scripting related requests 
Author Message

Joined: 2009-03-17 18:42:51
Posts: 3649
Reply with quote
ZaneZimer wrote:
I have a question not directly related to your additions to the viewer for executing Lua, but rather using Lua itself. I currently have a single .lua file and am using luac to compile it to bytecode for the viewer to pick up. All that works great, but my automation.lua is getting large especially since I have added serial/deserialize methods to make use of the new user data settings.

From what I have read, I should be able to create multiple .lua files and using luac combine them into a single bytecode file. A single file is created but I cannot seem to call any functions defined locally in the other files. I realize I can't create my own modules because of the 'require' restriction but I'm trying to achieve some form of compartmentalization of my own code since I will always compile. Maybe I just don't understand the usage of 'local' as it pertains to a separate file once it is compiled into bytecode. It seems to act more like it's private. I had been trying to avoid using globals in my automation.lua, maybe they are OK in the auxiliary files? Total noob at Lua. :?
Even loadfile() (and dofile(), which I forgot to disable, and will get disabled in tomorrow's release), you'd just execute the file as another chunk (i.e. in a "child" Lua state, with its own locality), so you won't be able to reach functions defined in that loaded file...

To achieve what you want, you may simply split your program into several *.lua files, then specify the said files (in the proper order, so that the main program that will call functions defined in other files, will be specified last) to luac:
Code:
luac5.3 -o automation.luac my_lua_functions.lua automation.lua


You could also use a pre-processor (like "cpp" in C/C++)... AFAIK, there is no official pre-processor for luac, but (under Linux, or with mingw/cygwin under Windows) you could just use cpp itself, using #include "some_included_lua_file.lua" in your main automation.lua "sources".

Example for automation.lua:
Code:
#include "my_lua_functions.lua"

hello_world()

Example for my_lua_functions.lua:
Code:
function hello_world()
    print("Hello world !")
end

Then, using cpp to assemble your Lua script and pass it to luac:
Code:
cpp -P -nostdinc -pipe automation.lua | luac5.3 -o automation.luac -

The "-P" option instructs cpp not to add its own comments/references in the output file (since luac won't understand them), "-nostdinc" tells it not to search for C headers outside the current directory (where both your "my_lua_functions.lua" and "automation.lua" should reside: if "my_lua_functions.lua" is elsewhere you can tell cpp with its "-I" option where to look for), and "-pipe" allows to send the resulting pre-processed sources to the standard output, which gets connected to the standard input of luac thanks to the pipe ("|") character and the "-" last option in luac's command line.

Now, check that it worked:
Code:
lua5.3 automation.luac
Which should print: Hello world !

As a bonus, you could use most cpp directives (#define, #if/#else/#endif, etc) in your code...


2017-02-24 21:49:58
Profile WWW

Joined: 2016-06-19 21:33:37
Posts: 88
Location: San Francisco bay area, CA, USA
Reply with quote
Great info, Henri. Thank you. The cpp trick was something I hadn't considered. I was trying for an all Lua solution.

I did managed to get something interesting going as follows:
Code:
<module.lua>
local util = function()
  print("I'm a utility")
end

Module = {
  util = util
}

return Module
<end module.lua>

<main.lua>
local function main(args)
  Module.util()
end

main()
<end main.lua>
As long as module.lua is loaded first, i.e. passed to luac before main.lua, things work pretty much like a regular module. The only drawback is that Module must be global. This seems to be similar to the syntax for a 'real' module that would need 'require' and could use a local Module declaration.


2017-02-25 00:25:03
Profile

Joined: 2016-06-19 21:33:37
Posts: 88
Location: San Francisco bay area, CA, USA
Reply with quote
What is the maximum size limit of the global/per account data items? I am currently serializing a relatively small 'config' table into the per account data but I do not wish to overrun the limits.

Any thoughts on using notecards for holding and reading in larger bits of data? Maybe in a read only capacity?

Cheers


2017-02-28 14:47:12
Profile

Joined: 2009-03-17 18:42:51
Posts: 3649
Reply with quote
ZaneZimer wrote:
What is the maximum size limit of the global/per account data items? I am currently serializing a relatively small 'config' table into the per account data but I do not wish to overrun the limits.

That's the limit of a string in a LLSD representation: practically "unlimited" (I just made a try with a 5+ millions characters string with SetGlobalData()/GetGlobalData() and it did work)...

Quote:
Any thoughts on using notecards for holding and reading in larger bits of data? Maybe in a read only capacity?
Notecards are way more limited (64K, IIRC) and they cannot be read on viewer start (only after a successful login), are slow to load, and may prove unreliable (asset server "hiccups"...). They would also not be suitable for anything else than per-account settings... Definitely a no-no.


2017-03-01 00:10:23
Profile WWW

Joined: 2016-06-19 21:33:37
Posts: 88
Location: San Francisco bay area, CA, USA
Reply with quote
Henri Beauchamp wrote:
That's the limit of a string in a LLSD representation: practically "unlimited" (I just made a try with a 5+ millions characters string with SetGlobalData()/GetGlobalData() and it did work)...
Ah, quite large then. That is more than enough for what I'm doing.
Henri Beauchamp wrote:
Notecards are way more limited (64K, IIRC) and they cannot be read on viewer start (only after a successful login), are slow to load, and may prove unreliable (asset server "hiccups"...). They would also not be suitable for anything else than per-account settings... Definitely a no-no.
That's fine. I was only pondering things that a user could edit that would drive script behavior and be 'file system safe'. Since the data values can store large strings, I am content to use them.


2017-03-01 00:19:58
Profile

Joined: 2016-06-19 21:33:37
Posts: 88
Location: San Francisco bay area, CA, USA
Reply with quote
Should the OnWindlightChange() event fire when 'Revert to region default' is selected? or any of the 'time of day' selections?


2017-03-18 20:00:37
Profile

Joined: 2009-03-17 18:42:51
Posts: 3649
Reply with quote
ZaneZimer wrote:
Should the OnWindlightChange() event fire when 'Revert to region default' is selected? or any of the 'time of day' selections?

Both OnWindlightChange() and ApplySkySettings() will be extended to take those into account.


2017-03-23 16:38:08
Profile WWW

Joined: 2016-06-19 21:33:37
Posts: 88
Location: San Francisco bay area, CA, USA
Reply with quote
Quote:
Both OnWindlightChange() and ApplySkySettings() will be extended to take those into account.
Thanks Henri. Both work nicely. I do notice that the Use Estate Time in the Environment Editor must not trigger the same action as Revert to region default, because the OnWindlightChange() doesn't seem to fire.


2017-03-25 19:50:59
Profile

Joined: 2009-03-17 18:42:51
Posts: 3649
Reply with quote
ZaneZimer wrote:
I do notice that the Use Estate Time in the Environment Editor must not trigger the same action as Revert to region default, because the OnWindlightChange() doesn't seem to fire.
Added for next release. Let me know if there are other places, in the viewer, where such changes can be triggered (I'm not too familiar with Windlight stuff, since I never use it myself)...


2017-03-25 23:10:41
Profile WWW

Joined: 2016-06-19 21:33:37
Posts: 88
Location: San Francisco bay area, CA, USA
Reply with quote
Quote:
I'm not too familiar with Windlight stuff, since I never use it myself
No worries. I don't/didn't much either. I have just been tinkering around with the Lua scripting and found this during testing.


2017-03-25 23:35:34
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 79 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6 ... 8  Next

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.