Toribash
Original Post
Upcoming Lua Changes
The upcoming beta release should be implementing these changes/additions/fixes to the lua implementation:
#########################
 L U A  C H A N G E L O G
#########################

    * Added "command" hook
        - Called when a /command is entered
        - Only picks up non recognised commands (so /set won't trigger it but /jalis will)
        - Example: /sdk/commandhooktest.lua
    
    * Added "unload" hook
        - Called before the script is unloaded.
        
    * New drawing functions:
        - draw_line | sdk/draw_line.lua
        - draw_triangle | sdk/draw_triangle.lua
        - draw_text_3d | sdk/draw_text_3d.lua
        - get_string_length | sdk/get_string_length.lua
    
    * Camera functions:
        - set_camera_mode | sdk/set_camera_mode.lua
        - fixed set_camera_pos for freecam mode
    
    * General functions:
        - get_files | sdk/get_files.lua
    
    * Modules:
        - Enabled use of lua modules
            ~ Examples in script/modules
            ~ Usage example sdk/ModuleUsageExample.lua
            ~ http://lua-users.org/wiki/ModulesTutorial
            ~ No c modules allowed.
        
    * OS Library: 
        - Enabled: 
            - os.time
            - os.date
            - os.difftime
            - os.tempname
            
    * IO Library:
        - Disabled:
            - io.popen
        - Changed:
            - If the third parameter is not nil, the directory will start in ./ as opposed to ./data/scripts
                ~ This keeps backwards compatibility, while enabling new features.
                
    * Documentation:
        - Added various functions to the sdk.
        - Changed some sdk documentation to be more clear.
Plus some fixes and probably a few more things I forgot.

The only backwards compatibility issues will be with any scripts that use io.popen and those that edited startup.lua

Documentation on how to use the functions will be provided in the SDK, or where it states in this changelog.

Any questions, ask them here.
Last edited by War_Hero; Mar 4, 2011 at 11:09 PM.
:D
I have some questions about get_files:

Will it return a file descriptor?
Will it work on directories besides the ones in the scripts tree?

About the Lua Changes, I've asked on another occasion about the possibility to have a mod automated in some way by a lua script and have both downloaded together when entering a multiplayer room running that mod. Is there any chance for that to happen in this release?

That would make it possible to have scene objects reacting in response to some in-game events.
Last edited by LastDuck; Mar 5, 2011 at 01:48 PM.
Originally Posted by LastDuck View Post
I have some questions about get_files:

Will it return a file descriptor?
Will it work on directories besides the ones in the scripts tree?

It simply returns the names of all files, no other data on the files. SDK file:

lua code:
-- get_files(string directory, string extension)

-- USE: Gets all files in a directory
-- NOTES: -

Files = get_files("data/script", "lua")

for i = 1, #Files do
echo(Files[i])
end



Originally Posted by LastDuck View Post
About the Lua Changes, I've asked on another occasion about the possibility to have a mod automated in some way by a lua script and have both downloaded together when entering a multiplayer room running that mod. Is there any chance for that to happen in this release?

That would make it possible to have scene objects reacting in response to some in-game events.

This is a feature being theorised and planned. No guarantee, however. Any suggestions for implementations are welcome, we currently have some different views on how to approach combining mods, scripts and online play and would like some feedback on which ways the community would like this sort of thing to be implemented.
:D
So I can use the files's names returned by get_files() as a parameter to io.open() EVEN if the file is not in the script directory, right?

As for the suggestions for implementation, sure I have a lot to share with you guys. Just let me organize it in a text, and then I'll bring it here for discussion.
Read the second io change :P

lua code:
a = io.open("data/mod/poop.tbm", "w", 1) --creates & opens data/mod/poop.tbm
b = io.open("poop.ini", "r") -- opens data/script/poop.ini
Last edited by Blam; Mar 5, 2011 at 08:52 PM.
:D
It seems that we cannot autorun scripts (by editing startup.lua) anymore... Is there another way to autorun a script ?

I know there are security issues if you let every scripts write some "dofile" in startup.lua, but maybe there is another way to run a script or just a hook at startup ?

Btw, I'm currently testing the new 3D primitives, great additions, thank you.
just make a new textfile, name it profile.tbs
and put ls <insert file name here>.lua into it.
(goes into the folder where the toribash exe is)
:■ :♥ :ß :¹ :↓ :► :· :°
Made a little api that you can use to add your scripts or other commands to autorun.

profile=io.open("profile.tbs","r",1)
if profile==nil then profile=io.open("profile.tbs","w",1) profile.close(profile) end

function profileAddScript(p)
profile=io.open("profile.tbs","a+",1)
profile:write("\nls "..tostring(p))
profile.close(profile)
end

function profileAddCommand(p)
profile=io.open("profile.tbs","a+",1)
profile:write("\n"..tostring(p))
profile.close(profile)
end
Use profileAddScript() to add a script and profileAddCommand() to add a command.
Attached Files
profileapi.lua (394 Bytes, 5 views)
multiple texture uploader! updated: multiple texture remover!
updated pretty colorlist!

<BobJoelZ> ok ive just rebooted my pc and ive tried to activate my reflex on yahoo internet explorer :/ no luck

<Aracoon> I do not enjoy having anal sex with multiple men
Mod/script integration would provide an extreme increase in mod quality and creativity. I support this idea fully.

I remember like a year ago in a chat with hampa, him mentioning lua + mod integration or alternate win conditions to be included in 4.0. Maybe it's time to revive the Mod Team. :P
- its been a while