Author Topic: a lua table into an array  (Read 10582 times)

0 Members and 1 Guest are viewing this topic.

Offline andrea.vermetti

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
a lua table into an array
« on: 26 May, 2005, 10:51:39 »
Hello people!!!!

I need a little help!!!!

How can get form a LUA FILE a teble and put it into an array

of string  in my C# class

string[] sss = xxxx["tableLua"].to String();


???


 

PtokaX forum

a lua table into an array
« on: 26 May, 2005, 10:51:39 »

Offline Dessamator

  • Scripter
  • Emperor
  • ******
  • Posts: 1 262
  • Karma: +13/-9
(No subject)
« Reply #1 on: 26 May, 2005, 14:29:13 »
hmmm, in lua a table is almost like an array so it wouldnt change much! but then u want to convert it to a string? well, each item has it value in the array or table, so u can convert it easily just use tostring(xxx["tablelua"])
Ignorance is Bliss.

Offline andrea.vermetti

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
(No subject)
« Reply #2 on: 26 May, 2005, 14:32:54 »
Thanck you!!!!!,,, i'm goin' to try!!!!!!!

Offline andrea.vermetti

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
it doesn't works....
« Reply #3 on: 26 May, 2005, 15:05:13 »
I get the table with this object (LuaInterface.LuaTable)

LuaInterface.LuaTable AWWAW= pluto.GetTable("a");

i get my table from lua file and now it becomes a c# objet....

so....

how can i test the lenght of AWWAW????

AWWAW.lenght();  it does not work
AWWAW.size();  it does not work


how can i get the AWWAW items and put them in my array

String[] str = new String[];

for (int i = 0, to  (AWWAW.lenght-1), i++)
{
 str  =  AWWAW(i)

}

HELP ME PLEASE!!!!!!!!!!!!

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
(No subject)
« Reply #4 on: 26 May, 2005, 16:21:08 »
Hi i'm using simulair code in my menu for robocop. So i know what ya mean or looking for, but i'm writting it in VB.Net so i can't tell ya how it should look in C#

I will ask some 1 else to help you...

Darn she got a lovely smile  :D

Laterss Optimus

Offline andrea.vermetti

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
(No subject)
« Reply #5 on: 26 May, 2005, 16:38:55 »
I'm using .net but in c# not vb...


how can i do the thinghs i'm doin with vb. dotnet????

how do you import lua DLLs?????

help me please....

if i could use vb......


i'm loosing a lot of time with c# (java)....

somebody say that's java is better......

HELP!!!!!!!!!!!!!

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
(No subject)
« Reply #6 on: 26 May, 2005, 17:18:50 »
Quote
I'm using .net but in c# not vb...


how can i do the thinghs i'm doin with vb. dotnet????

how do you import lua DLLs?????

help me please....

if i could use vb......


i'm loosing a lot of time with c# (java)....

somebody say that's java is better......

HELP!!!!!!!!!!!!!

Code: [Select]
' Import the LUA interface
Imports LuaInterface
Imports System.IO

Public Class frmRobocop
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Private LUA As LUA

    Private Sub frmRobocop_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Intialize the Lua interface
        LUA = New Lua

        'Open LUA libraries
        LUA.OpenBaseLib()
        LUA.OpenDebugLib()
        LUA.OpenIOLib()
        LUA.OpenMathLib()
        LUA.OpenStringLib()
        LUA.OpenTableLib()

        Try
            'Dofile our needed files/tables
            LUA.DoFile(Application.StartupPath + "\system\robocoplua.lua") 'Store you lua code in here that can be called for later use
            LUA.DoFile(Application.StartupPath + "\settings.tbl")
            LUA.DoFile(Application.StartupPath + "\tbl\scriptlevel.tbl")
            ''LUA.DoFile(Application.StartupPath + "\tbl\inbuildlevel.tbl")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

        'Register object for use in lua
        LUA("TextBox_Txt") = TextBox_Txt

        'Trigger LUA event, called StartRoboCopLUA (this function is in my case stored in the file robocoplua.lua)
        Try
            LUA.GetFunction("StartRoboCopLUA").Call()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub


This gives you an idea what can be done

- Optimus

Offline kepp

  • Scripter
  • King
  • ******
  • Posts: 790
  • Karma: +2/-0
(No subject)
« Reply #7 on: 26 May, 2005, 17:42:26 »
The LUA.NET package is great..
The only thing i miss of it is iteration of tables etc..

You must know position or key to enter value in table from C#

You use LuaTable LT = LUA.GetTable("MyTable");
now you enter it with LT[Number] or LT[Key]

If you really want to iterate over a table i recomend you to register a C# Array to LUA;

Create the C# Array and register it with LUA["MyCArray"] = ArrayObject;

now, you can write code with LUA.Dostring();
Iterate the table you want and insert it to the C# Array

for i,v in MyLuaTable do
   MyCArray:Add(v)
end
return 1;

Upon return 1 you are ready to access the content.
Just play around, you will figure it out somehow and eventually it will be clearer to you what i mean
Guarding    

Offline CaSaNoVa

  • Member
  • ***
  • Posts: 43
  • Karma: +1/-0
Andrea?
« Reply #8 on: 26 May, 2005, 18:16:23 »
Andrea ma sei la gnocca in foto? :D

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #9 on: 26 May, 2005, 18:18:59 »
Kepp that is not the right way to seduse a lady you know.

btw mate your KEY will never fit...  :D

Btw: Are you really a girl andrea.vermetti

I want to now so I can keep messing with kepp.  :P

LoooooL // NL
//NL

Offline kepp

  • Scripter
  • King
  • ******
  • Posts: 790
  • Karma: +2/-0
(No subject)
« Reply #10 on: 26 May, 2005, 19:03:21 »
Code: [Select]

[COLOR=green]/* Open needed libraries */[/COLOR]

Lua LUA = new Lua();
LUA.OpenBaseLib();
LUA.OpenMathLib();
...
...
[COLOR=green]
/*
To register the objUser class with LUA first intialize it then
decide name for it to use in lua:
*/[/COLOR]

LUA["Sexbomb"] = objUser;

[COLOR=green]
/* The code below show you how this class can be used within LUA */[/COLOR]

Sexbomb.sPhonenumber = Sexbomb:AskPhoneNumber()
Sexbomb.sAddress = Sexbomb:AskAddress();
Sexbomb.bBiggyBoob = Sexbomb:AskBoobs();


private class objUser
{
private string mstrPhoneno = null;
private string mstrAddress = null;
private bool   mboolBigbo = false;

[COLOR=green]/* Some class properties */[/COLOR]
public string sPhonenumber
{
get {return mstrPhoneno;}
set {mstrPhoneno = value;}
}

public string sAddress
{
get {return mstrAddress;}
set {mstrAddress = value;}
}

public bool bBiggyBoob
{
get {return mboolBigbo;}
set {mboolBigbo = value;}
}

[COLOR=green]/* Class function */[/COLOR]
public string AskPhonenumber()
{
Console.WriteLine("What is your phone number??");
return Console.ReadLine();
}

public string AskAddress()
{
Console.WriteLine("What is your address?");
return Console.ReadLine();
}

public bool AskBoobs()
{
Console.WriteLine("Are they big?");
return Convert.ToBoolean(Console.ReadLine());
}
}

[COLOR=green]
/*
To get tables from LUA you should use LuaTable class.
Problem is that you cannot iterate over the table elements with this class!
I just came up with a solution to this problem which will return a lua table as
an Hashtable in C#
*/
[/COLOR]


function Hashtable GetLUATable(string Tablename)
{
Hashtable tmp = new Hashtable();
LUA["Hashtable"] = tmp; [COLOR=green]// Register out temp Hashtable to LUA[/COLOR]

[COLOR=green]// Put values in table into Hashtable[/COLOR]
LUA.DoString("for i,v in " + Tablename + " do " +
    "Hashtable:Add(i,v) " +
    "end")

LUA["Hashtable"] = null; [COLOR=green]// Converted to nil[/COLOR]
return tmp;
}

[COLOR=green]
/* Now you have a returned Hashtable, were you can iterate over both Index and Keys.
the Hashtable is accessed from System.Collections..
I havwe not tested above function but should perform the task
*/
[/COLOR]

****
GetLUATable function shall be C# function so change to C#
« Last Edit: 26 May, 2005, 19:07:46 by kepp »
Guarding    

Offline 6Marilyn6Manson6

  • Scripter
  • King
  • ******
  • Posts: 869
  • Karma: +47/-35
    • http://www.marilynmanson986.altervista.org
(No subject)
« Reply #11 on: 26 May, 2005, 19:49:29 »
Andrea molto gnocca complimenti :D

Offline CaSaNoVa

  • Member
  • ***
  • Posts: 43
  • Karma: +1/-0
ehhh
« Reply #12 on: 26 May, 2005, 20:21:07 »
Sperando ke sia lei eh^_^

Offline andrea.vermetti

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
(No subject)
« Reply #13 on: 27 May, 2005, 09:08:15 »
Thank you everybody!!!!!!

You resolved all my trubles!!!!!


KISSES


for italian kids.....

yes i'm pretty girl from Reggio Emilia!!!!

Offline CaSaNoVa

  • Member
  • ***
  • Posts: 43
  • Karma: +1/-0
LoL
« Reply #14 on: 28 May, 2005, 03:24:27 »
Hi Andrea^_^

I knew you're a pretty italian girl^_^

Post me if u want speake about ptokax and scripts ;)

Offline kepp

  • Scripter
  • King
  • ******
  • Posts: 790
  • Karma: +2/-0
(No subject)
« Reply #15 on: 28 May, 2005, 17:18:15 »
Yea or me...
PM me and i'll ya anything you want to know ;)
Guarding    

PtokaX forum

(No subject)
« Reply #15 on: 28 May, 2005, 17:18:15 »