Language:
C     Change language:
Pastebin: 92162
Author: Anonymous
Subject: Re: Untitled
Created: 2008-07-21 20:00:02
Download and save
Toggle line numbers
1static int lua_pgeUsbInit(lua_State *L) 
2
3    int argc = lua_gettop(L); 
4 
5    if(argc != 0
6        return luaL_error(L, "Argument error: pgeUsb.init() takes no arguments."); 
7 
8    lua_pushboolean(L, pgeUsbInit()); 
9 
10    return 1
11
12 
13static int lua_pgeUsbShutdown(lua_State *L) 
14
15    int argc = lua_gettop(L); 
16 
17    if(argc != 0
18        return luaL_error(L, "Argument error: pgeUsb.shutdown() takes no arguments."); 
19 
20    pgeUsbShutdown(); 
21 
22    return 0
23
24 
25static int lua_pgeUsbActivate(lua_State *L) 
26
27    int argc = lua_gettop(L); 
28 
29    if(argc != 0
30        return luaL_error(L, "Argument error: pgeUsb.activate() takes no arguments."); 
31 
32    lua_pushboolean(L, pgeUsbActivate()); 
33 
34    return 1
35
36 
37static int lua_pgeUsbDeactivate(lua_State *L) 
38
39    int argc = lua_gettop(L); 
40 
41    if(argc != 0
42        return luaL_error(L, "Argument error: pgeUsb.deactivate() takes no arguments."); 
43 
44    lua_pushboolean(L, pgeUsbDeactivate()); 
45 
46    return 1
47
48 
49static int lua_pgeUsbActivated(lua_State *L) 
50
51    int argc = lua_gettop(L); 
52 
53    if(argc != 0
54        return luaL_error(L, "Argument error: pgeUsb.activated() takes no arguments."); 
55 
56    int state = pgeUsbGetState(); 
57 
58    lua_pushboolean(L, state & PGE_USB_ACTIVATED); 
59 
60    return 1
61
62 
63static int lua_pgeUsbCableConnected(lua_State *L) 
64
65    int argc = lua_gettop(L); 
66 
67    if(argc != 0
68        return luaL_error(L, "Argument error: pgeUsb.cable() takes no arguments."); 
69 
70    int state = pgeUsbGetState(); 
71 
72    lua_pushboolean(L, state & PGE_USB_CABLE_CONNECTED); 
73 
74    return 1
75
76 
77static int lua_pgeUsbEstablished(lua_State *L) 
78
79    int argc = lua_gettop(L); 
80 
81    if(argc != 0
82        return luaL_error(L, "Argument error: pgeUsb.established() takes no arguments."); 
83 
84    int state = pgeUsbGetState(); 
85 
86    lua_pushboolean(L, state & PGE_USB_CONNECTION_ESTABLISHED); 
87 
88    return 1
89
90 
91static const luaL_reg lua_pgeUsb_functions[] = 
92
93    {"init",           lua_pgeUsbInit}, 
94    {"shutdown",       lua_pgeUsbShutdown}, 
95    {"activate",       lua_pgeUsbActivate}, 
96    {"deactivate",     lua_pgeUsbDeactivate}, 
97    {"activated",      lua_pgeUsbActivated}, 
98    {"cable",          lua_pgeUsbCableConnected}, 
99    {"established",        lua_pgeUsbEstablished}, 
100    {0, 0
101}; 
102 
103int lua_pgeUsb_init(lua_State *L) 
104
105    lua_newtable(L); 
106    luaL_register(L, 0, lua_pgeUsb_functions); 
107    return 1
108
109 
110static const luaL_reg pgeModules[] = 
111
112    {"pge",        lua_pge_init}, 
113    {"pge.wav",        lua_pgeWav_init}, 
114    {"pge.controls",       lua_pgeControls_init}, 
115    {"pge.math",       lua_pgeMath_init}, 
116    {"pge.mp3",        lua_pgeMp3_init}, 
117    {"pge.texture",        lua_pgeTexture_init}, 
118    {"pge.timer",      lua_pgeTimer_init}, 
119    {"pge.gfx",        lua_pgeGfx_init}, 
120    {"pge.file",       lua_pgeFile_init}, 
121    {"pge.font",       lua_pgeFont_init}, 
122    {"pge.net",        lua_pgeNet_init}, 
123    {"pge.zip",        lua_pgeZip_init}, 
124    {"pge.utils",      lua_pgeUtils_init}, 
125    {"pge.usb",        lua_pgeUsb_init}, 
126    {0, 0
127}; 
128 
129 
130------------------------------------ 
131 
132Init code: 
133 
134int pgeLuaRunScript(const char *scriptpath) 
135
136    int error = 0
137 
138    char errortext[1024]; 
139 
140    const char *errormsg = NULL
141 
142    L = lua_open(); 
143 
144    luaL_openlibs(L); 
145 
146    lua_getglobal(L, "package"); 
147    lua_getfield(L, -1, "preload"); 
148    luaL_register(L, 0, pgeModules); 
149    lua_pop(L, 2); // package and package.preload 
150 
151    error = luaL_loadfile(L, scriptpath); 
152 
153    if(error == 0
154        error = lua_pcall(L, 0, LUA_MULTRET, 0); 
155 
156    if(error) 
157    { 
158        errormsg = lua_tostring(L, -1); 
159        sprintf(errortext, "Error: %s\n", lua_tostring(L, -1)); 
160        pgeLuaDebugOutput(errortext); 
161        lua_pop(L, 1); 
162    } 
163 
164    lua_close(L); 
165 
166    return error; 
167
Download and save
Toggle line numbers
Thread:
[92158] Untitled by Anonymous at 2008-07-21 19:50:39 (diff)
  [92162] Re: Untitled by Anonymous at 2008-07-21 20:00:02
    [92163] Re: Untitled by Anonymous at 2008-07-21 20:00:37 (diff)
Tip: Click the line numbers to toggle highliting on that line.

Paste followup:

Language:
Author:
Subject:


    Tabstop:     bigger biggest
Note: You can prefix a line with "@@@" to highlight it.