Thursday, 20 November 2008
 
  Home arrow Forum  
Main Menu
Home
News
Forum
Documentation
Download
Links
Administrator
Login Form
Welcome, Guest. Please login or register.
November 20, 2008, 05:56:06 AM
Username: Password:
Login with username, password and session length

Forgot your password?
Using DSLua with PHP
DSLua Community
Welcome, Guest. Please login or register.
November 20, 2008, 05:56:06 AM
1723 Posts in 315 Topics by 5662 Members
Latest Member: oberomub
DSLua Community  |  DSLua - Best scripting language for Nintendo DS  |  Examples/Tutorials  |  Using DSLua with PHP « previous next »
Pages: [1]
Author Topic: Using DSLua with PHP  (Read 2250 times)
Jeremysr
Waxing Gibbous
****
Posts: 254



WWW
« 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
« Last Edit: January 24, 2007, 12:16:03 PM by Jeremysr » Logged
daltonlaffs
Waxing Gibbous
****
Posts: 340


Freaking Insane


WWW
« Reply #1 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!
Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
Jeremysr
Waxing Gibbous
****
Posts: 254



WWW
« Reply #2 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 Smiley (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.)
Logged
Salz`
New Moon
*
Posts: 1


« Reply #3 on: June 19, 2008, 07:23:37 PM »

Just use "+" instead of %20.
Logged
Pages: [1]
« previous next »
    Jump to:  



    (C) 2008 DSLua

    DSLua - Best scripting language for Nintendo DS home-brew!