DSLua Community

DSLua - Best scripting language for Nintendo DS => Examples/Tutorials => Topic started by: Jeremysr on January 22, 2007, 05:34:53 PM



Title: Using DSLua with PHP
Post by: Jeremysr on January 22, 2007, 05:34:53 PM
I found out how to use Wifi to pass variables to .php scripts on the internet. You can just put them in the URL. Here are the programs I made.

dslua_php.lua:

Code:
require( "keyboard.inc.lua" )

SCREEN_TOP = 1
SCREEN_BOTTOM = 0

BGTopText = Screen.LoadTextBG()
Screen.Initialize( SCREEN_TOP, BGTopText )

BGTopText:PrintXY( 0, 0, "Connecting to WFC..." )
Wifi.ConnectWFC()
BGTopText:Clear()

function ReceiveMessage()
BGTopText:Clear()
receive_message = ""
Wifi.GetHTTP( "http://www.bio-gaming.com/dslua.php", receive_message )
BGTopText:PrintXY( 0, 0, receive_message )
end

function SendMessage( msg )
msg = string.gsub( msg, " ", "." )
unusedvariable = ""
Wifi.GetHTTP( "http://www.bio-gaming.com/dslua.php?msg=" .. msg, unusedvariable )
ReceiveMessage()
end

while Pads.Start() == false do
BGTopText:PrintXY( 0, 23, "A - Send             B - Receive" )
if Pads.A() then
while Pads.A() do end
msg = keyboard()
SendMessage( msg )
end
if Pads.B() then
while Pads.B() do end
ReceiveMessage()
end
end

dslua.php :

Code:
<?php

if (isset($_GET['msg'])) {
$file fopen("dslua.txt""w");
fwrite($filestr_replace("."" "$_GET['msg']));
} else {
$file fopen("dslua.txt""r");
$message fgets($file);
echo ($message);
}

?>


It stores the text in dslua.txt on my site. You can send and receive messages (each time overwriting dslua.txt) using the lua program, or using your web browser (type "bio-gaming.com/dslua.php" to see the current message or "bio-gaming.com/dslua.php?msg=insert.message.here" to send a message.) BTW spaces don't seem to work yet so don't use them! Edit: Fixed the spaces!

Oh and you'll need to download keyboard and put it in the same directory as the lua script for it to work: http://www.bio-gaming.com/jeremy/dslua/index.php?act=keyboard


Title: Re: Using DSLua with PHP
Post by: daltonlaffs on January 23, 2007, 06:32:15 PM
Nice discovery, Jeremysr. This makes a PHP editor possible! *pokes sypherce about keyboard again*

Aaanyway, I have found a way to add spaces. Use the %20 tag as a space. Like this:

http://bio-gaming.com/dslua.php?msg=space>%20lol!

I'm gonna put this on my php hoster (4000mb) and try it on another php!

NICE DISCOVERY!


Title: Re: Using DSLua with PHP
Post by: Jeremysr on January 23, 2007, 06:38:50 PM
I know about the %20 but it doesn't seem to work with the Wifi.GetHTTP() function. A solution would be to change all the spaces into "."'s or something before sending, then with the PHP change the "."'s into spaces before displaying. I'll try it. *edits the scripts in first post*

Quote
Nice discovery, Jeremysr. This makes a PHP editor possible! *pokes sypherce about keyboard again*

I've already added a keyboard to DSLua 0.7 :) (I just have to find out how to make it work when it's on top of other backgrounds. Right now it only works when there isn't anything else being displayed on the bottoms screen.)


Title: Re: Using DSLua with PHP
Post by: Salz` on June 19, 2008, 07:23:37 PM
Just use "+" instead of %20.